Do not walk into type sub-nodes for cast/conv expr (#10616)
This commit is contained in:
parent
1e88bf1def
commit
0c4d1fd10b
2 changed files with 24 additions and 0 deletions
|
|
@ -601,6 +601,12 @@ proc p(n: PNode; c: var Con): PNode =
|
||||||
of nkNone..nkNilLit, nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef,
|
of nkNone..nkNilLit, nkTypeSection, nkProcDef, nkConverterDef, nkMethodDef,
|
||||||
nkIteratorDef, nkMacroDef, nkTemplateDef, nkLambda, nkDo, nkFuncDef:
|
nkIteratorDef, nkMacroDef, nkTemplateDef, nkLambda, nkDo, nkFuncDef:
|
||||||
result = n
|
result = n
|
||||||
|
of nkCast, nkHiddenStdConv, nkHiddenSubConv, nkConv:
|
||||||
|
result = copyNode(n)
|
||||||
|
# Destination type
|
||||||
|
result.add n[0]
|
||||||
|
# Analyse the inner expression
|
||||||
|
result.add p(n[1], c)
|
||||||
else:
|
else:
|
||||||
result = copyNode(n)
|
result = copyNode(n)
|
||||||
recurse(n, result)
|
recurse(n, result)
|
||||||
|
|
|
||||||
18
tests/destructor/tcast.nim
Normal file
18
tests/destructor/tcast.nim
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
discard """
|
||||||
|
cmd: '''nim c --newruntime $file'''
|
||||||
|
"""
|
||||||
|
|
||||||
|
# Make sure we don't walk cast[T] type section while injecting sinks/destructors
|
||||||
|
block:
|
||||||
|
type
|
||||||
|
XY[T] = object
|
||||||
|
discard
|
||||||
|
|
||||||
|
proc `=`[T](x: var XY[T]; v: XY[T]) {.error.}
|
||||||
|
proc `=sink`[T](x: var XY[T]; v: XY[T]) {.error.}
|
||||||
|
|
||||||
|
proc main[T]() =
|
||||||
|
var m = cast[ptr XY[T]](alloc0(sizeof(XY[T])))
|
||||||
|
doAssert(m != nil)
|
||||||
|
|
||||||
|
main[int]()
|
||||||
Loading…
Add table
Add a link
Reference in a new issue