From 9474a818afa95f682d1255e74fae1681a2b4f1de Mon Sep 17 00:00:00 2001 From: Jasper Jenkins Date: Sun, 5 Jan 2020 00:18:14 -0800 Subject: [PATCH] fix enumtostr crash for enum-range (#13035) --- compiler/ccgexprs.nim | 2 +- tests/enum/tenum_no_rtti.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/enum/tenum_no_rtti.nim diff --git a/compiler/ccgexprs.nim b/compiler/ccgexprs.nim index 8c41fb370fc5..6d5f255670c1 100644 --- a/compiler/ccgexprs.nim +++ b/compiler/ccgexprs.nim @@ -2070,7 +2070,7 @@ proc genDispose(p: BProc; n: PNode) = proc genEnumToStr(p: BProc, e: PNode, d: var TLoc) = const ToStringProcSlot = -4 - let t = e[1].typ.skipTypes(abstractInst) + let t = e[1].typ.skipTypes(abstractInst+{tyRange}) var toStrProc: PSym = nil for idx, p in items(t.methods): if idx == ToStringProcSlot: diff --git a/tests/enum/tenum_no_rtti.nim b/tests/enum/tenum_no_rtti.nim new file mode 100644 index 000000000000..2e5c74b35699 --- /dev/null +++ b/tests/enum/tenum_no_rtti.nim @@ -0,0 +1,12 @@ +discard """ + output: '''A +B''' + cmd: '''nim c --gc:arc $file''' +""" +type + Enum = enum A, B, C + EnumRange = range[A .. B] +proc test_a(x: Enum): string = $x +proc test_b(x: EnumRange): string = $x +echo test_a(A) +echo test_b(B)