Skip to content

Commit

Permalink
test disabling partial generics altogether
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 27, 2024
1 parent 77d7a08 commit a8b7388
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 19 deletions.
6 changes: 3 additions & 3 deletions compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ proc initCandidateSymbols(c: PContext, headSymbol: PNode,
symx = nextOverloadIter(o, c, headSymbol)
if result.len > 0:
best = initCandidate(c, result[0].s, initialBinding,
result[0].scope, result.len == 1, diagnostics)
result[0].scope, diagnostics)
alt = initCandidate(c, result[0].s, initialBinding,
result[0].scope, result.len == 1, diagnostics)
result[0].scope, diagnostics)
best.state = csNoMatch

proc pickBestCandidate(c: PContext, headSymbol: PNode,
Expand Down Expand Up @@ -97,7 +97,7 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
var z: TCandidate # current candidate
while true:
determineType(c, sym)
z = initCandidate(c, sym, initialBinding, scope, syms.len == 1, diagnosticsFlag)
z = initCandidate(c, sym, initialBinding, scope, diagnosticsFlag)

# this is kinda backwards as without a check here the described
# problems in recalc would not happen, but instead it 100%
Expand Down
20 changes: 6 additions & 14 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ proc matchGenericParam(m: var TCandidate, formal: PType, n: PNode) =
m.firstMismatch.kind = kGenericParamTypeMismatch
return

proc matchGenericParams*(m: var TCandidate, binding: PNode, callee: PSym,
allowPartialInst = true) =
proc matchGenericParams*(m: var TCandidate, binding: PNode, callee: PSym) =
let c = m.c
let typeParams = callee.ast[genericParamsPos]
let paramCount = typeParams.len
Expand Down Expand Up @@ -192,16 +191,10 @@ proc matchGenericParams*(m: var TCandidate, binding: PNode, callee: PSym,
m.state = csEmpty
return
else:
if allowPartialInst:
# only providing some generic parameters is permitted
# if symbol is not overloaded
# but a sym still cannot be created
m.state = csEmpty
else:
m.state = csNoMatch
m.firstMismatch.kind = kMissingGenericParam
m.firstMismatch.arg = i
m.firstMismatch.formal = paramSym
m.state = csNoMatch
m.firstMismatch.kind = kMissingGenericParam
m.firstMismatch.arg = i
m.firstMismatch.formal = paramSym
return
m.state = csMatch

Expand Down Expand Up @@ -232,7 +225,6 @@ proc copyingEraseVoidParams(m: TCandidate, t: var PType) =

proc initCandidate*(ctx: PContext, callee: PSym,
binding: PNode, calleeScope = -1,
singleSym = false,
diagnosticsEnabled = false): TCandidate =
result = initCandidateAux(ctx, callee.typ)
result.calleeSym = callee
Expand All @@ -245,7 +237,7 @@ proc initCandidate*(ctx: PContext, callee: PSym,
result.magic = result.calleeSym.magic
result.bindings = initTypeMapping()
if binding != nil:
matchGenericParams(result, binding, callee, allowPartialInst = singleSym)
matchGenericParams(result, binding, callee)
let genericMatch = result.state
if genericMatch != csNoMatch:
result.state = csEmpty
Expand Down
4 changes: 2 additions & 2 deletions tests/generics/timplicit_and_explicit.nim
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ block: # basic test
proc doStuff[T](a: SomeInteger): T = discard
proc doStuff[T;Y](a: SomeInteger, b: Y): Y = discard
assert typeof(doStuff[int](100)) is int
assert typeof(doStuff[int](100, 1.0)) is float
assert typeof(doStuff[int](100, "Hello")) is string
assert typeof(doStuff[int, float](100, 1.0)) is float
assert typeof(doStuff[int, string](100, "Hello")) is string

proc t[T](x: T; z: int | float): seq[T] = result.add(x & $z)

Expand Down

0 comments on commit a8b7388

Please sign in to comment.