fixes #2304
This commit is contained in:
parent
ea5217c9fc
commit
13cdad8819
4 changed files with 22 additions and 5 deletions
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
11
tests/generics/tarray_with_somenumber.nim
Normal file
11
tests/generics/tarray_with_somenumber.nim
Normal 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)
|
||||
Loading…
Add table
Add a link
Reference in a new issue