Skip to content

Commit d85c032

Browse files
authored
fixes #25127; disable lent types as object fields in returns (#25189)
fixes #25127
1 parent 6938fce commit d85c032

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

compiler/typeallowed.nim

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ when defined(nimPreviewSlimSystem):
1818

1919
type
2020
TTypeAllowedFlag* = enum
21-
taField,
21+
taTupField, # field of a tuple
22+
taObjField, # field of an object
2223
taHeap,
2324
taConcept,
2425
taIsOpenArray,
@@ -69,8 +70,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
6970
result = t
7071
elif taIsOpenArray in flags:
7172
result = t
72-
elif t.kind == tyLent and ((kind != skResult and views notin c.features) or
73-
(kind == skParam and {taIsCastable, taField} * flags == {})): # lent cannot be used as parameters.
73+
elif t.kind == tyLent and (((kind != skResult or taObjField in flags) and views notin c.features) or
74+
(kind == skParam and {taIsCastable, taObjField, taTupField} * flags == {})): # lent cannot be used as parameters.
7475
# except in the cast environment and as the field of an object
7576
result = t
7677
elif isOutParam(t) and kind != skParam:
@@ -187,12 +188,12 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
187188
t.baseClass != nil and taIsDefaultField notin flags:
188189
result = t
189190
else:
190-
let flags = flags+{taField, taVoid}
191+
let flags = flags+{taObjField, taVoid}
191192
result = typeAllowedAux(marker, t.baseClass, kind, c, flags)
192193
if result.isNil and t.n != nil:
193194
result = typeAllowedNode(marker, t.n, kind, c, flags)
194195
of tyTuple:
195-
let flags = flags+{taField, taVoid}
196+
let flags = flags+{taTupField, taVoid}
196197
for a in t.kids:
197198
result = typeAllowedAux(marker, a, kind, c, flags)
198199
if result != nil: break

0 commit comments

Comments
 (0)