From 03653ab61e6eed6811c5df0677a2bf2aa722ef9c Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Fri, 21 Apr 2017 22:28:34 +0200 Subject: [PATCH] Fix type inference with static literals. Fixes #3977 --- compiler/semstmts.nim | 2 +- tests/generics/t3977.nim | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 tests/generics/t3977.nim diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim index 3687e50e9c..7213601de5 100644 --- a/compiler/semstmts.nim +++ b/compiler/semstmts.nim @@ -498,7 +498,7 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode = def = fitNode(c, typ, def, def.info) #changeType(def.skipConv, typ, check=true) else: - typ = skipIntLit(def.typ) + typ = def.typ.skipTypes({tyStatic}).skipIntLit if typ.kind in tyUserTypeClasses and typ.isResolvedUserTypeClass: typ = typ.lastSon if hasEmpty(typ): diff --git a/tests/generics/t3977.nim b/tests/generics/t3977.nim new file mode 100644 index 0000000000..3140177447 --- /dev/null +++ b/tests/generics/t3977.nim @@ -0,0 +1,12 @@ +discard """ + output: '''42''' +""" + +type + Foo[N: static[int]] = object + +proc foo[N](x: Foo[N]) = + echo N + +var f1: Foo[42] +f1.foo