Skip to content

Commit

Permalink
make typeof accept symchoices [backport:2.0]
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 23, 2024
1 parent cb7bcae commit c1b5191
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
22 changes: 22 additions & 0 deletions tests/lookups/t24002.nim
Original file line number Diff line number Diff line change
@@ -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)

0 comments on commit c1b5191

Please sign in to comment.