From 9b98add6c714474e261df1a0a17819282dfd1975 Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Sat, 14 Jul 2018 01:44:40 +0200 Subject: [PATCH] Do not crash while instantiating a generic outside a call (#8279) Fixes #8270 --- compiler/sigmatch.nim | 5 ++++- tests/generics/t8270.nim | 7 +++++++ 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 tests/generics/t8270.nim diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 4bac3d3ea2..7e9143d94e 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -569,7 +569,10 @@ proc procParamTypeRel(c: var TCandidate, f, a: PType): TTypeRelation = # signature. There is a change that the target # type is already fully-determined, so we are # going to try resolve it - f = generateTypeInstance(c.c, c.bindings, c.call.info, f) + if c.call != nil: + f = generateTypeInstance(c.c, c.bindings, c.call.info, f) + else: + f = nil if f == nil or f.isMetaType: # no luck resolving the type, so the inference fails return isBothMetaConvertible diff --git a/tests/generics/t8270.nim b/tests/generics/t8270.nim new file mode 100644 index 0000000000..707e981fab --- /dev/null +++ b/tests/generics/t8270.nim @@ -0,0 +1,7 @@ +discard """ + line: 6 + errormsg: "cannot instantiate: \'T\'" +""" + +proc m[T](x: T): int = discard +echo [m]