This commit is contained in:
Araq 2015-03-15 20:36:07 +01:00
commit 13cdad8819
4 changed files with 22 additions and 5 deletions

View file

@ -919,6 +919,8 @@ const
# only used when 'gCmd == cmdPretty': Indicates that the symbol has been # only used when 'gCmd == cmdPretty': Indicates that the symbol has been
# imported via 'importc: "fullname"' and no format string. # imported via 'importc: "fullname"' and no format string.
var ggDebug* {.deprecated.}: bool ## convenience switch for trying out things
proc isCallExpr*(n: PNode): bool = proc isCallExpr*(n: PNode): bool =
result = n.kind in nkCallKinds result = n.kind in nkCallKinds

View file

@ -352,7 +352,7 @@ proc semAnonTuple(c: PContext, n: PNode, prev: PType): PType =
for i in countup(0, sonsLen(n) - 1): for i in countup(0, sonsLen(n) - 1):
addSonSkipIntLit(result, semTypeNode(c, n.sons[i], nil)) 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 var typ: PType
result = newOrPrevType(tyTuple, prev, c) result = newOrPrevType(tyTuple, prev, c)
result.n = newNodeI(nkRecList, n.info) 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) var m = newCandidate(c, t)
matches(c, n, copyTree(n), m) matches(c, n, copyTree(n), m)
if m.state != csMatch: if m.state != csMatch and not m.typedescMatched:
var err = "cannot instantiate " & typeToString(t) & "\n" & let err = "cannot instantiate " & typeToString(t) & "\n" &
"got: (" & describeArgs(c, n) & ")\n" & "got: (" & describeArgs(c, n) & ")\n" &
"but expected: (" & describeArgs(c, t.n, 0) & ")" "but expected: (" & describeArgs(c, t.n, 0) & ")"
localError(n.info, errGenerated, err) localError(n.info, errGenerated, err)

View file

@ -46,7 +46,7 @@ type
# be instantiated # be instantiated
coerceDistincts*: bool # this is an explicit coercion that can strip away coerceDistincts*: bool # this is an explicit coercion that can strip away
# a distrinct type # a distrinct type
typedescMatched: bool typedescMatched*: bool
inheritancePenalty: int # to prefer closest father object type inheritancePenalty: int # to prefer closest father object type
errors*: CandidateErrors # additional clarifications to be displayed to the errors*: CandidateErrors # additional clarifications to be displayed to the
# user if overload resolution fails # user if overload resolution fails
@ -989,7 +989,11 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation =
else: else:
internalAssert a.sons != nil and a.sons.len > 0 internalAssert a.sons != nil and a.sons.len > 0
c.typedescMatched = true 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 if result > isGeneric: result = isGeneric
else: else:
result = isNone result = isNone

View file

@ -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)