Fix varargs int32 (#11054)

* fixes #10999
* adds a test for #10999
This commit is contained in:
Arne Döring 2019-04-18 20:53:57 +02:00 • committed by Andreas Rumpf
commit a55817f9ac
2 changed files with 22 additions and 5 deletions

View file

@ -2092,14 +2092,21 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
result = localConvMatch(c, m, f, a, arg) result = localConvMatch(c, m, f, a, arg)
else: else:
r = typeRel(m, base(f), a) r = typeRel(m, base(f), a)
if r >= isGeneric: case r
of isGeneric:
inc(m.convMatches) inc(m.convMatches)
result = copyTree(arg) result = copyTree(arg)
if r == isGeneric:
result.typ = getInstantiatedType(c, arg, m, base(f)) result.typ = getInstantiatedType(c, arg, m, base(f))
m.baseTypeMatch = true m.baseTypeMatch = true
# bug #4799, varargs accepting subtype relation object of isFromIntLit:
elif r == isSubtype: inc(m.intConvMatches, 256)
result = implicitConv(nkHiddenStdConv, f[0], arg, m, c)
m.baseTypeMatch = true
of isEqual:
inc(m.convMatches)
result = copyTree(arg)
m.baseTypeMatch = true
of isSubtype: # bug #4799, varargs accepting subtype relation object
inc(m.subtypeMatches) inc(m.subtypeMatches)
if base(f).kind == tyTypeDesc: if base(f).kind == tyTypeDesc:
result = arg result = arg

View file

@ -2,6 +2,7 @@ discard """
output: '''(1, 1) output: '''(1, 1)
(2, 2) (2, 2)
(3, 3) (3, 3)
@[1, 2, 3, 4]
''' '''
""" """
@ -15,3 +16,12 @@ proc foo(args: varargs[int]) =
discard discard
foo(1,2,3) foo(1,2,3)
# 10999
proc varargsToSeq(vals: varargs[int32]): seq[int32] =
result = newSeqOfCap[int32](vals.len)
for v in vals:
result.add v
echo varargsToSeq(1, 2, 3, 4)