mirror of
https://github.com/nim-lang/Nim.git
synced 2025-12-28 17:04:41 +00:00
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:
@@ -2071,6 +2071,7 @@ proc paramTypesMatchAux(m: var TCandidate, f, a: PType,
|
||||
# constructor in a call:
|
||||
if result == nil and f.kind == tyVarargs:
|
||||
if f.n != nil:
|
||||
# Forward to the varargs converter
|
||||
result = localConvMatch(c, m, f, a, arg)
|
||||
else:
|
||||
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
|
||||
elif r == isSubtype:
|
||||
inc(m.subtypeMatches)
|
||||
if f.kind == tyTypeDesc:
|
||||
if base(f).kind == tyTypeDesc:
|
||||
result = arg
|
||||
else:
|
||||
result = implicitConv(nkHiddenSubConv, f, arg, m, c)
|
||||
result = implicitConv(nkHiddenSubConv, base(f), arg, m, c)
|
||||
m.baseTypeMatch = true
|
||||
else:
|
||||
result = userConvMatch(c, m, base(f), a, arg)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
output: "OK"
|
||||
"""
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
outputsub: '''ObjectAssignmentError'''
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
outputsub: '''ObjectAssignmentError'''
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
discard """
|
||||
targets: "c cpp"
|
||||
outputsub: '''ObjectAssignmentError'''
|
||||
exitcode: "1"
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user