mirror of
https://github.com/nim-lang/Nim.git
synced 2026-07-22 00:41:28 +00:00
* fixes #21674; `lent` can be used in the fields or the cast type as a parameter
* add a test case
* fix the test
(cherry picked from commit 65223e6f59)
This commit is contained in:
@@ -232,7 +232,7 @@ proc isCastable(c: PContext; dst, src: PType, info: TLineInfo): bool =
|
||||
return false
|
||||
elif srcSize < 0:
|
||||
return false
|
||||
elif typeAllowed(dst, skParam, c) != nil:
|
||||
elif typeAllowed(dst, skParam, c, {taIsCastable}) != nil:
|
||||
return false
|
||||
elif dst.kind == tyProc and dst.callConv == ccClosure:
|
||||
return src.kind == tyProc and src.callConv == ccClosure
|
||||
|
||||
@@ -22,6 +22,7 @@ type
|
||||
taNoUntyped
|
||||
taIsTemplateOrMacro
|
||||
taProcContextIsNotMacro
|
||||
taIsCastable
|
||||
|
||||
TTypeAllowedFlags* = set[TTypeAllowedFlag]
|
||||
|
||||
@@ -60,7 +61,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
|
||||
elif taIsOpenArray in flags:
|
||||
result = t
|
||||
elif t.kind == tyLent and ((kind != skResult and views notin c.features) or
|
||||
kind == skParam): # lent can't be used as parameters.
|
||||
(kind == skParam and {taIsCastable, taField} * flags == {})): # lent cannot be used as parameters.
|
||||
# except in the cast environment and as the field of an object
|
||||
result = t
|
||||
else:
|
||||
var t2 = skipTypes(t[0], abstractInst-{tyTypeDesc, tySink})
|
||||
|
||||
@@ -77,3 +77,19 @@ type Inner = object
|
||||
var o = Outer(value: 1234)
|
||||
var v = Inner(owner: o).owner.value
|
||||
doAssert v == 1234
|
||||
|
||||
block: # bug #21674
|
||||
type
|
||||
Lent = object
|
||||
data: lent int
|
||||
|
||||
proc foo(s: Lent) =
|
||||
var m = 12
|
||||
discard cast[lent int](m)
|
||||
|
||||
proc main =
|
||||
var m1 = 123
|
||||
var x = Lent(data: m1)
|
||||
foo(x)
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user