From 04c48e3c5b7a98b065d9f3a96575a304a60a9290 Mon Sep 17 00:00:00 2001 From: Bung Date: Fri, 21 Oct 2022 15:26:46 +0800 Subject: fix #19426 compile error using when/elif/else and typedesc in template (#20550) --- tests/whenstmt/t19426.nim | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 tests/whenstmt/t19426.nim (limited to 'tests/whenstmt') diff --git a/tests/whenstmt/t19426.nim b/tests/whenstmt/t19426.nim new file mode 100644 index 000000000..95fb54a9e --- /dev/null +++ b/tests/whenstmt/t19426.nim @@ -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() \ No newline at end of file -- cgit 1.4.1-2-gfad0