Skip to content

Commit

Permalink
add testcase for overloadable_enums (nim-lang#18722)
Browse files Browse the repository at this point in the history
* add testcase for overloadable_enums

* link
  • Loading branch information
ringabout authored Aug 21, 2021
1 parent e52221e commit f0c6593
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/enum/toverloadable_enums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,32 @@ proc takeCallback(param: proc(p: int)) = discard
takeCallback x

echo ord v

block: # https://github.com/nim-lang/RFCs/issues/8
type
Enum1 = enum
A, B, C
Enum2 = enum
A, Z

proc f(e: Enum1): int = ord(e)
proc g(e: Enum2): int = ord(e)

proc h(e: Enum1): int = ord(e)
proc h(e: Enum2): int = ord(e)

let fA = f(A) # Type of A is well defined
let gA = g(A) # Same as above

let hA1 = h(Enum1.A) # A requires disambiguation
let hA2 = h(Enum2.A) # Similarly
let hA3 = h(B)
let hA4 = h(B)
let x = ord(Enum1.A) # Also
doAssert fA == 0
doAssert gA == 0
doAssert hA1 == 0
doAssert hA2 == 0
doAssert x == 0
doAssert hA3 == 1
doAssert hA4 == 1

0 comments on commit f0c6593

Please sign in to comment.