-
-
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.
fix range[enum] type conversion (#13204) [backport]
- Loading branch information
Showing
2 changed files
with
36 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
discard """ | ||
cmd: "nim check --hints:off $file" | ||
errormsg: "type mismatch: got <BC>" | ||
nimout: ''' | ||
tenums.nim(32, 20) Error: type mismatch: got <Letters> | ||
but expected one of: | ||
proc takesChristmasColor(color: ChristmasColors) | ||
first type mismatch at position: 1 | ||
required type for color: ChristmasColors | ||
but expression 'A' is of type: Letters | ||
expression: takesChristmasColor(A) | ||
tenums.nim(33, 20) Error: type mismatch: got <BC> | ||
but expected one of: | ||
proc takesChristmasColor(color: ChristmasColors) | ||
first type mismatch at position: 1 | ||
required type for color: ChristmasColors | ||
but expression 'BC(C)' is of type: BC | ||
expression: takesChristmasColor(BC(C)) | ||
''' | ||
""" | ||
|
||
type | ||
Colors = enum Red, Green, Blue | ||
ChristmasColors = range[Red .. Green] | ||
Letters = enum A, B, C | ||
BC = range[B .. C] | ||
|
||
proc takesChristmasColor(color: ChristmasColors) = discard | ||
takesChristmasColor(Green) | ||
takesChristmasColor(A) | ||
takesChristmasColor(BC(C)) |