fixes #25441; fixes #7355; deletes void args from the argument list (#25455)

fixes #25441; fixes #7355

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
ringabout
2026-01-24 13:08:38 +08:00
committed by GitHub
parent 469e1377cd
commit 81610095e6
5 changed files with 37 additions and 9 deletions

View File

@@ -830,6 +830,21 @@ proc inheritBindings(c: PContext, x: var TCandidate, expectedType: PType) =
for i in 0 ..< flatUnbound.len():
x.bindings.put(flatUnbound[i], flatBound[i])
proc compactVoidArgs(n: PNode): PNode =
# deletes void args from the argument list, which are created by `setSon`
var hasNil = false
for i in 0..<n.len:
if n[i] == nil:
hasNil = true
break
if not hasNil:
result = n
else:
result = copyNode(n)
for i in 0..<n.len:
if n[i] != nil:
result.add n[i]
proc semResolvedCall(c: PContext, x: var TCandidate,
n: PNode, flags: TExprFlags;
expectedType: PType = nil): PNode =
@@ -880,7 +895,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate,
markUsed(c, info, finalCallee, isGenericInstance = true)
onUse(info, finalCallee, isGenericInstance = true)
result = x.call
result = compactVoidArgs(x.call)
instGenericConvertersSons(c, result, x)
markConvertersUsed(c, result)
result[0] = newSymNode(finalCallee, getCallLineInfo(result[0]))

View File

@@ -832,9 +832,6 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp
proc fixAbstractType(c: PContext, n: PNode) =
for i in 1..<n.len:
let it = n[i]
if it == nil:
localError(c.config, n.info, "'$1' has nil child at index $2" % [renderTree(n, {renderNoComments}), $i])
return
# do not get rid of nkHiddenSubConv for OpenArrays, the codegen needs it:
if it.kind == nkHiddenSubConv and
skipTypes(it.typ, abstractVar).kind notin {tyOpenArray, tyVarargs}:
@@ -1155,7 +1152,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType
localError(c.config, n.info, msg)
return errorNode(c, n)
else:
result = m.call
result = compactVoidArgs(m.call)
instGenericConvertersSons(c, result, m)
markConvertersUsed(c, result)

View File

@@ -3092,6 +3092,7 @@ proc matches*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
put(m, formal.typ, defaultValue.typ)
defaultValue.flags.incl nfDefaultParam
setSon(m.call, formal.position + 1, defaultValue)
# forget all inferred types if the overload matching failed
if m.state == csNoMatch:
for t in m.inferredTypes:

19
tests/generics/tvoids.nim Normal file
View File

@@ -0,0 +1,19 @@
block: # bug #25441
func foo[T](x: T, y: int) =
discard
foo[void](10)
block:
func foo[T: void|float](e: openArray[int], x: T, y: int) =
discard
var x: seq[int]
foo[void] x, 2
block: # bug #7355
proc gen[A: void, T: void|int](a: A, b: T) = discard
gen[void, void]() # Works
gen[void, int] 0 # Crash
gen[void, int](b = 0) # Crash

View File

@@ -1,7 +1,3 @@
discard """
errormsg: "'blk.p(a)' has nil child at index 1"
action: reject
"""
import macros
type BlockLiteral[T] = object