@@ -86,7 +86,7 @@ proc ithField(t: PType, field: var FieldTracker): FieldInfo =
86
86
base = b.baseClass
87
87
result = ithField (t.n, field)
88
88
89
- proc annotateType * (n: PNode , t: PType ; conf: ConfigRef ) =
89
+ proc annotateType * (n: PNode , t: PType ; conf: ConfigRef ; producedClosure: var bool ) =
90
90
let x = t.skipTypes (abstractInst+ {tyRange})
91
91
# Note: x can be unequal to t and we need to be careful to use 't'
92
92
# to not to skip tyGenericInst
@@ -102,7 +102,7 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
102
102
globalError conf, n.info, " invalid field at index " & $ i
103
103
else :
104
104
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 )
106
106
if field.delete:
107
107
# only codegen fields from active case branches
108
108
incl (n[i].flags, nfPreventCg)
@@ -111,9 +111,11 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
111
111
n.typ () = t
112
112
for i in 0 ..< n.len:
113
113
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 )
115
115
elif x.kind == tyProc and x.callConv == ccClosure:
116
116
n.typ () = t
117
+ if n.len > 1 and n[1 ].kind notin {nkEmpty, nkNilLit}:
118
+ producedClosure = true
117
119
elif x.kind == tyOpenArray: # `opcSlice` transforms slices into tuples
118
120
if n.kind == nkTupleConstr:
119
121
let
@@ -125,11 +127,11 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
125
127
of nkStrKinds:
126
128
for i in left.. right:
127
129
bracketExpr.add newIntNode (nkCharLit, BiggestInt n[0 ].strVal[i])
128
- annotateType (bracketExpr[^ 1 ], x.elementType, conf)
130
+ annotateType (bracketExpr[^ 1 ], x.elementType, conf, producedClosure )
129
131
of nkBracket:
130
132
for i in left.. right:
131
133
bracketExpr.add n[0 ][i]
132
- annotateType (bracketExpr[^ 1 ], x.elementType, conf)
134
+ annotateType (bracketExpr[^ 1 ], x.elementType, conf, producedClosure )
133
135
else :
134
136
globalError (conf, n.info, " Incorrectly generated tuple constr" )
135
137
n[] = bracketExpr[]
@@ -140,18 +142,18 @@ proc annotateType*(n: PNode, t: PType; conf: ConfigRef) =
140
142
of nkBracket:
141
143
if x.kind in {tyArray, tySequence, tyOpenArray}:
142
144
n.typ () = t
143
- for m in n: annotateType (m, x.elemType, conf)
145
+ for m in n: annotateType (m, x.elemType, conf, producedClosure )
144
146
else :
145
147
globalError (conf, n.info, " [] must have some form of array type" )
146
148
of nkCurly:
147
149
if x.kind in {tySet}:
148
150
n.typ () = t
149
151
for m in n:
150
152
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 )
153
155
else :
154
- annotateType (m, x.elemType, conf)
156
+ annotateType (m, x.elemType, conf, producedClosure )
155
157
else :
156
158
globalError (conf, n.info, " {} must have the set type" )
157
159
of nkFloatLit.. nkFloat128Lit:
0 commit comments