mirror of
https://github.com/nim-lang/Nim.git
synced 2026-02-11 22:08:54 +00:00
fixes #25441; fixes #7355
---------
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
(cherry picked from commit 81610095e6)
This commit is contained in:
@@ -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]))
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -3093,6 +3093,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
19
tests/generics/tvoids.nim
Normal 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
|
||||
@@ -1,7 +1,3 @@
|
||||
discard """
|
||||
errormsg: "'blk.p(a)' has nil child at index 1"
|
||||
action: reject
|
||||
"""
|
||||
import macros
|
||||
|
||||
type BlockLiteral[T] = object
|
||||
|
||||
Reference in New Issue
Block a user