From d80397c7d79d1d7837f6d7c0fb0bfb0d5e443c5e Mon Sep 17 00:00:00 2001 From: Andreas Rumpf Date: Tue, 4 Jul 2023 23:35:25 +0200 Subject: [PATCH] fixes #22138 (#22221) (cherry picked from commit 86ff37fab8656f7acd08fc9c3fa237f9e022dbf4) --- compiler/sigmatch.nim | 9 +++++++-- tests/lent/tlent_from_var.nim | 20 ++++++++++++++++++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 558f4d6e8e..0b7d0e6634 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -1634,7 +1634,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, elif a.len > 0 and a.lastSon == f: # Needed for checking `Y` == `Addable` in the following #[ - type + type Addable = concept a, type A a + a is A MyType[T: Addable; Y: static T] = object @@ -1901,7 +1901,12 @@ proc implicitConv(kind: TNodeKind, f: PType, arg: PNode, m: TCandidate, if result.typ == nil: internalError(c.graph.config, arg.info, "implicitConv") result.add c.graph.emptyNode - result.add arg + if arg.typ != nil and arg.typ.kind == tyLent: + let a = newNodeIT(nkHiddenDeref, arg.info, arg.typ[0]) + a.add arg + result.add a + else: + result.add arg proc isLValue(c: PContext; n: PNode): bool {.inline.} = let aa = isAssignable(nil, n) diff --git a/tests/lent/tlent_from_var.nim b/tests/lent/tlent_from_var.nim index 912390dc16..d61ff6dc00 100644 --- a/tests/lent/tlent_from_var.nim +++ b/tests/lent/tlent_from_var.nim @@ -30,3 +30,23 @@ let x2 = x.byLentVar let xs2 = xs.byLentVar echo xs2 + +# bug #22138 + +type Xxx = object + +type + Opt[T] = object + case oResultPrivate*: bool + of false: + discard + of true: + vResultPrivate*: T + +func value*[T: not void](self: Opt[T]): lent T {.inline.} = + self.vResultPrivate +template get*[T: not void](self: Opt[T]): T = self.value() + +method connect*( + self: Opt[(int, int)]) = + discard self.get()[0]