@@ -86,7 +86,7 @@ proc ithField(t: PType, field: var FieldTracker): FieldInfo =
8686 base = b.baseClass
8787 result = ithField (t.n, field)
8888
89- proc annotateType * (n: PNode , t: PType ; conf: ConfigRef ) =
89+ proc annotateType * (n: PNode , t: PType ; conf: ConfigRef ; producedClosure: var bool ) =
9090 let x = t.skipTypes (abstractInst+ {tyRange})
9191 # Note: x can be unequal to t and we need to be careful to use 't'
9292 # to not to skip tyGenericInst
@@ -102,7 +102,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
102102 globalError conf, n.info, " invalid field at index " & $ i
103103 else :
104104 internalAssert (conf, n[i].kind == nkExprColonExpr)
105- annotateType (n[i][1 ], field.sym.typ, conf)
105+ annotateType (n[i][1 ], field.sym.typ, conf, producedClosure )
106106 if field.delete:
107107 # only codegen fields from active case branches
108108 incl (n[i].flags, nfPreventCg)
@@ -111,9 +111,11 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
111111 n.typ () = t
112112 for i in 0 ..< n.len:
113113 if i >= x.kidsLen: globalError conf, n.info, " invalid field at index " & $ i
114- else : annotateType (n[i], x[i], conf)
114+ else : annotateType (n[i], x[i], conf, producedClosure )
115115 elif x.kind == tyProc and x.callConv == ccClosure:
116116 n.typ () = t
117+ if n.len > 1 and n[1 ].kind notin {nkEmpty, nkNilLit}:
118+ producedClosure = true
117119 elif x.kind == tyOpenArray: # `opcSlice` transforms slices into tuples
118120 if n.kind == nkTupleConstr:
119121 let
@@ -125,11 +127,11 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
125127 of nkStrKinds:
126128 for i in left.. right:
127129 bracketExpr.add newIntNode (nkCharLit, BiggestInt n[0 ].strVal[i])
128- annotateType (bracketExpr[^ 1 ], x.elementType, conf)
130+ annotateType (bracketExpr[^ 1 ], x.elementType, conf, producedClosure )
129131 of nkBracket:
130132 for i in left.. right:
131133 bracketExpr.add n[0 ][i]
132- annotateType (bracketExpr[^ 1 ], x.elementType, conf)
134+ annotateType (bracketExpr[^ 1 ], x.elementType, conf, producedClosure )
133135 else :
134136 globalError (conf, n.info, " Incorrectly generated tuple constr" )
135137 n[] = bracketExpr[]
@@ -140,18 +142,18 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
140142 of nkBracket:
141143 if x.kind in {tyArray, tySequence, tyOpenArray}:
142144 n.typ () = t
143- for m in n: annotateType (m, x.elemType, conf)
145+ for m in n: annotateType (m, x.elemType, conf, producedClosure )
144146 else :
145147 globalError (conf, n.info, " [] must have some form of array type" )
146148 of nkCurly:
147149 if x.kind in {tySet}:
148150 n.typ () = t
149151 for m in n:
150152 if m.kind == nkRange:
151- annotateType (m[0 ], x.elemType, conf)
152- annotateType (m[1 ], x.elemType, conf)
153+ annotateType (m[0 ], x.elemType, conf, producedClosure )
154+ annotateType (m[1 ], x.elemType, conf, producedClosure )
153155 else :
154- annotateType (m, x.elemType, conf)
156+ annotateType (m, x.elemType, conf, producedClosure )
155157 else :
156158 globalError (conf, n.info, " {} must have the set type" )
157159 of nkFloatLit.. nkFloat128Lit:
0 commit comments