From 217a2cf0982302b9d89d2c06fc96eaf72f0518fe Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Mon, 16 Jul 2018 16:19:31 +0200 Subject: [PATCH] Resolve converter call to constants in case arms (#8336) Fixes #8333 --- compiler/semtypes.nim | 5 ++++- tests/casestmt/t8333.nim | 10 ++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 tests/casestmt/t8333.nim diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 17420111f1..25d8674b86 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -557,7 +557,10 @@ proc semCaseBranch(c: PContext, t, branch: PNode, branchIndex: int, return elif r.kind notin {nkCurly, nkBracket} or len(r) == 0: checkMinSonsLen(t, 1, c.config) - branch.sons[i] = skipConv(fitNode(c, t.sons[0].typ, r, r.info)) + var tmp = fitNode(c, t.sons[0].typ, r, r.info) + # the call to fitNode may introduce a call to a converter + if tmp.kind in {nkHiddenCallConv}: tmp = semConstExpr(c, tmp) + branch.sons[i] = skipConv(tmp) inc(covered) else: if r.kind == nkCurly: diff --git a/tests/casestmt/t8333.nim b/tests/casestmt/t8333.nim new file mode 100644 index 0000000000..ca35233581 --- /dev/null +++ b/tests/casestmt/t8333.nim @@ -0,0 +1,10 @@ +discard """ + output: "1" +""" + +converter toInt*(x: char): int = + x.int + +case 0 +of 'a': echo 0 +else: echo 1