fix range[enum] type conversion (#13204) [backport]
This commit is contained in:
parent
470faa97c6
commit
0606b6a44e
2 changed files with 36 additions and 2 deletions
33
tests/range/tenums.nim
Normal file
33
tests/range/tenums.nim
Normal file
|
|
@ -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))
|
||||
Loading…
Add table
Add a link
Reference in a new issue