From 13cdad88197ded8e0a81b990dd877848b9e50c10 Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 15 Mar 2015 20:36:07 +0100 Subject: [PATCH] fixes #2304 --- compiler/ast.nim | 2 ++ compiler/semtypes.nim | 6 +++--- compiler/sigmatch.nim | 8 ++++++-- tests/generics/tarray_with_somenumber.nim | 11 +++++++++++ 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 tests/generics/tarray_with_somenumber.nim diff --git a/compiler/ast.nim b/compiler/ast.nim index ab315877a..0c9f4bffc 100644 --- a/compiler/ast.nim +++ b/compiler/ast.nim @@ -919,6 +919,8 @@ const # only used when 'gCmd == cmdPretty': Indicates that the symbol has been # imported via 'importc: "fullname"' and no format string. +var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things + proc isCallExpr*(n: PNode): bool = result = n.kind in nkCallKinds diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 8a9f4a988..902ac52b0 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -352,7 +352,7 @@ proc semAnonTuple(c: PContext, n: PNode, prev: PType): PType = for i in countup(0, sonsLen(n) - 1): addSonSkipIntLit(result, semTypeNode(c, n.sons[i], nil)) -proc semTuple(c: PContext, n: PNode, prev: PType): PType = +proc semTuple(c: PContext, n: PNode, prev: PType): PType = var typ: PType result = newOrPrevType(tyTuple, prev, c) result.n = newNodeI(nkRecList, n.info) @@ -1045,8 +1045,8 @@ proc semGeneric(c: PContext, n: PNode, s: PSym, prev: PType): PType = var m = newCandidate(c, t) matches(c, n, copyTree(n), m) - if m.state != csMatch: - var err = "cannot instantiate " & typeToString(t) & "\n" & + if m.state != csMatch and not m.typedescMatched: + let err = "cannot instantiate " & typeToString(t) & "\n" & "got: (" & describeArgs(c, n) & ")\n" & "but expected: (" & describeArgs(c, t.n, 0) & ")" localError(n.info, errGenerated, err) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index e56d82a5b..38340ffb7 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -46,7 +46,7 @@ type # be instantiated coerceDistincts*: bool # this is an explicit coercion that can strip away # a distrinct type - typedescMatched: bool + typedescMatched*: bool inheritancePenalty: int # to prefer closest father object type errors*: CandidateErrors # additional clarifications to be displayed to the # user if overload resolution fails @@ -989,7 +989,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = else: internalAssert a.sons != nil and a.sons.len > 0 c.typedescMatched = true - result = typeRel(c, f.base, a.skipTypes({tyGenericParam, tyTypeDesc})) + var aa = a + while aa.kind in {tyTypeDesc, tyGenericParam} and + aa.len > 0: + aa = lastSon(aa) + result = typeRel(c, f.base, aa) if result > isGeneric: result = isGeneric else: result = isNone diff --git a/tests/generics/tarray_with_somenumber.nim b/tests/generics/tarray_with_somenumber.nim new file mode 100644 index 000000000..0bf2537a1 --- /dev/null +++ b/tests/generics/tarray_with_somenumber.nim @@ -0,0 +1,11 @@ +discard """ + output: '''@[0.9, 0.1]''' +""" + +# bug #2304 + +type TV2*[T:SomeNumber] = array[0..1, T] +proc newV2T*[T](x, y: T=0): TV2[T] = [x, y] + +let x = newV2T[float](0.9, 0.1) +echo(@x)