From c1b5191300f7e3c29336d30adfbce2338762da96 Mon Sep 17 00:00:00 2001 From: metagn Date: Fri, 23 Aug 2024 12:35:54 +0300 Subject: [PATCH] make typeof accept symchoices [backport:2.0] refs #24002 --- compiler/semexprs.nim | 2 +- tests/lookups/t24002.nim | 22 ++++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 tests/lookups/t24002.nim diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 9293f8497b15..e9e85ce242a0 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -144,7 +144,7 @@ proc semSymChoice(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: P if isSymChoice(result) and result.len == 1: # resolveSymChoice can leave 1 sym result = result[0] - if isSymChoice(result) and efAllowSymChoice notin flags: + if isSymChoice(result) and {efAllowSymChoice, efInTypeof} * flags == {}: var err = "ambiguous identifier: '" & result[0].sym.name.s & "' -- use one of the following:\n" for child in n: diff --git a/tests/lookups/t24002.nim b/tests/lookups/t24002.nim new file mode 100644 index 000000000000..4aee40741707 --- /dev/null +++ b/tests/lookups/t24002.nim @@ -0,0 +1,22 @@ +discard """ + action: compile # for now just test that it compiles +""" + +# issue #24002 + +type Result[T, E] = object + +func value*[T, E](self: Result[T, E]): T {.inline.} = + discard + +func value*[T: not void, E](self: var Result[T, E]): var T {.inline.} = + discard + +template unrecognizedFieldWarning = + echo typeof value + +proc readValue*(value: var int) = + unrecognizedFieldWarning() + +var foo: int +readValue(foo)