Fix subtype conversion w/ varargs arguments (#10402)
The type matching is done on the `T` of the `varargs[T]` so the conversion must be performed to `T` and not to the whole type. This problem is only noticeable with the cpp backend since C doesn't give a damn shit about your fucking (wrong) types. Fixes #9845
This commit is contained in:
parent
ae5d8fbd9d
commit
ee89ba6bdb
5 changed files with 7 additions and 2 deletions
|
|
@ -2071,6 +2071,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
|
||||||
# constructor in a call:
|
# constructor in a call:
|
||||||
if result == nil and f.kind == tyVarargs:
|
if result == nil and f.kind == tyVarargs:
|
||||||
if f.n != nil:
|
if f.n != nil:
|
||||||
|
# Forward to the varargs converter
|
||||||
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)
|
||||||
|
|
@ -2083,10 +2084,10 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
|
||||||
# bug #4799, varargs accepting subtype relation object
|
# bug #4799, varargs accepting subtype relation object
|
||||||
elif r == isSubtype:
|
elif r == isSubtype:
|
||||||
inc(m.subtypeMatches)
|
inc(m.subtypeMatches)
|
||||||
if f.kind == tyTypeDesc:
|
if base(f).kind == tyTypeDesc:
|
||||||
result = arg
|
result = arg
|
||||||
else:
|
else:
|
||||||
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
|
result = implicitConv(nkHiddenSubConv, base(f), arg, m, c)
|
||||||
m.baseTypeMatch = true
|
m.baseTypeMatch = true
|
||||||
else:
|
else:
|
||||||
result = userConvMatch(c, m, base(f), a, arg)
|
result = userConvMatch(c, m, base(f), a, arg)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
output: "OK"
|
output: "OK"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentError'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentError'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
discard """
|
discard """
|
||||||
|
targets: "c cpp"
|
||||||
outputsub: '''ObjectAssignmentError'''
|
outputsub: '''ObjectAssignmentError'''
|
||||||
exitcode: "1"
|
exitcode: "1"
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue