-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolve unambiguous enum symchoices from local scope, error on rest (#…
…22606) fixes #22598, properly fixes #21887 and fixes test case issue number When an enum field sym choice has to choose a type, check if its name is ambiguous in the local scope, then check if the first symbol found in the local scope is the first symbol in the sym choice. If so, choose that symbol. Otherwise, give an ambiguous identifier error. The dependence on the local scope implies this will always give ambiguity errors for unpicked enum symchoices from generics and templates and macros from other scopes. We can change `not isAmbiguous(...) and foundSym == first` to `not (isAmbiguous(...) and foundSym == first)` to make it so they never give ambiguity errors, and always pick the first symbol in the symchoice. I can do this if this is preferred, but no code from CI seems affected.
- Loading branch information
Showing
5 changed files
with
67 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
discard """ | ||
cmd: "nim check --hints:off $file" | ||
""" | ||
|
||
block: # bug #21887 | ||
type | ||
EnumA = enum A = 300, B | ||
EnumB = enum A = 10 | ||
EnumC = enum C | ||
|
||
doAssert typeof(EnumC(A)) is EnumC #[tt.Error | ||
^ ambiguous identifier 'A' -- use one of the following: | ||
EnumA.A: EnumA | ||
EnumB.A: EnumB]# | ||
|
||
block: # issue #22598 | ||
type | ||
A = enum | ||
red | ||
B = enum | ||
red | ||
|
||
let a = red #[tt.Error | ||
^ ambiguous identifier 'red' -- use one of the following: | ||
A.red: A | ||
B.red: B]# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters