From d85c0324b7432d688722888cbcdf24fba67b70b5 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Tue, 23 Sep 2025 19:04:27 +0800 Subject: [PATCH] fixes #25127; disable `lent` types as object fields in returns (#25189) fixes #25127 --- compiler/typeallowed.nim | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/typeallowed.nim b/compiler/typeallowed.nim index a814597e27..80b532371c 100644 --- a/compiler/typeallowed.nim +++ b/compiler/typeallowed.nim @@ -18,7 +18,8 @@ when defined(nimPreviewSlimSystem): type TTypeAllowedFlag* = enum - taField, + taTupField, # field of a tuple + taObjField, # field of an object taHeap, taConcept, taIsOpenArray, @@ -69,8 +70,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = t elif taIsOpenArray in flags: result = t - elif t.kind == tyLent and ((kind != skResult and views notin c.features) or - (kind == skParam and {taIsCastable, taField} * flags == {})): # lent cannot be used as parameters. + elif t.kind == tyLent and (((kind != skResult or taObjField in flags) and views notin c.features) or + (kind == skParam and {taIsCastable, taObjField, taTupField} * flags == {})): # lent cannot be used as parameters. # except in the cast environment and as the field of an object result = t elif isOutParam(t) and kind != skParam: @@ -187,12 +188,12 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, t.baseClass != nil and taIsDefaultField notin flags: result = t else: - let flags = flags+{taField, taVoid} + let flags = flags+{taObjField, taVoid} result = typeAllowedAux(marker, t.baseClass, kind, c, flags) if result.isNil and t.n != nil: result = typeAllowedNode(marker, t.n, kind, c, flags) of tyTuple: - let flags = flags+{taField, taVoid} + let flags = flags+{taTupField, taVoid} for a in t.kids: result = typeAllowedAux(marker, a, kind, c, flags) if result != nil: break