implements overloadable enum values; WIP (#18470)

* implements overloadable enum values
* simpler code
This commit is contained in:
Andreas Rumpf 2021-07-28 12:46:28 +02:00 • committed by GitHub
commit a273ea70e8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 125 additions and 11 deletions

View file

@ -0,0 +1,48 @@
discard """
output: '''B
0'''
joinable: false
"""
{.experimental: "overloadableEnums".}
type
E1 = enum
value1,
value2
E2 = enum
value1,
value2 = 4
const
Lookuptable = [
E1.value1: "1",
value2: "2"
]
when false:
const
Lookuptable: array[E1, string] = [
value1: "1",
value2: "2"
]
proc p(e: E1): int =
# test that the 'case' statement is smart enough:
case e
of value1: echo "A"
of value2: echo "B"
let v = p value2 # ERROR: ambiguous!
# (value2|value2) nkClosedSymChoice -> nkSym
proc x(p: int) = discard
proc x(p: string) = discard
proc takeCallback(param: proc(p: int)) = discard
takeCallback x
echo ord v