fix #19426 compile error using when/elif/else and typedesc in template (#20550)

This commit is contained in:
Bung 2022-10-21 15:26:46 +08:00 • committed by GitHub
commit 04c48e3c5b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

16
tests/whenstmt/t19426.nim Normal file
View file

@ -0,0 +1,16 @@
type
MyInt = object
bitWidth: int
template toRealType*(t: MyInt): typedesc =
when t.bitWidth == 32: int32
elif t.bitWidth == 64: int64
else: {.error.}
proc doFail(T: typedesc): T = default(T)
proc test =
const myInt = MyInt(bitWidth:32)
discard doFail(toRealType(myInt))
test()