Skip to content

Commit

Permalink
delay procvar check logic to semFinishOperands
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Jan 8, 2024
1 parent 62d8ca4 commit 6b2f102
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 18 deletions.
35 changes: 24 additions & 11 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,6 @@ proc semOperand(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
# same as 'semExprWithType' but doesn't check for proc vars
result = semExpr(c, n, flags + {efOperand, efAllowSymChoice})
if result.typ != nil:
# XXX tyGenericInst here?
if result.typ.kind == tyProc and hasUnresolvedParams(result, {efOperand}):
#and tfUnresolved in result.typ.flags:
let owner = result.typ.owner
let err =
# consistent error message with evaltempl/semMacroExpr
if owner != nil and owner.kind in {skTemplate, skMacro}:
errMissingGenericParamsForTemplate % n.renderTree
else:
errProcHasNoConcreteType % n.renderTree
localError(c.config, n.info, err)
if result.typ.kind in {tyVar, tyLent}: result = newDeref(result)
elif {efWantStmt, efAllowStmt} * flags != {}:
result.typ = newTypeS(tyVoid, c)
Expand Down Expand Up @@ -1013,6 +1002,30 @@ proc bracketedMacro(n: PNode): PSym =
else:
result = nil

proc finishOperand(c: PContext, a: PNode): PNode =
if a.typ.isNil:
result = c.semOperand(c, a, {efDetermineType})
else:
result = a
# XXX tyGenericInst here?
if result.typ.kind == tyProc and hasUnresolvedParams(result, {efOperand}):
#and tfUnresolved in result.typ.flags:
let owner = result.typ.owner
let err =
# consistent error message with evaltempl/semMacroExpr
if owner != nil and owner.kind in {skTemplate, skMacro}:
errMissingGenericParamsForTemplate % a.renderTree
else:
errProcHasNoConcreteType % a.renderTree
localError(c.config, a.info, err)
considerGenSyms(c, result)

proc semFinishOperands(c: PContext; n: PNode) =
# this needs to be called to ensure that after overloading resolution every
# argument has been sem'checked:
for i in 1..<n.len:
n[i] = finishOperand(c, n[i])

proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
if efNoSemCheck notin flags and n.typ != nil and n.typ.kind == tyError:
return errorNode(c, n)
Expand Down
5 changes: 5 additions & 0 deletions compiler/semtypinst.nim
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ proc handleGenericInvocation(cl: var TReplTypeVars, t: PType): PType =
if header == t: header = instCopyType(cl, t)
header[i] = x
propagateToOwner(header, x)
elif isUnresolvedStatic(x) and not (cl.allowMetaTypes or tfRetType in x.flags):
# copied from error for unbound generic param in lookupTypeVar in above branch
localError(cl.c.config, cl.info, "cannot instantiate: '" & typeToString(x) & "'")
header[i] = errorType(cl.c)
propagateToOwner(header, x)
else:
propagateToOwner(header, x)

Expand Down
6 changes: 0 additions & 6 deletions compiler/sigmatch.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2704,12 +2704,6 @@ proc matchesAux(c: PContext, n, nOrig: PNode, m: var TCandidate, marker: var Int
m.firstMismatch.arg = a
m.firstMismatch.formal = formal

proc semFinishOperands*(c: PContext, n: PNode) =
# this needs to be called to ensure that after overloading resolution every
# argument has been sem'checked:
for i in 1..<n.len:
n[i] = prepareOperand(c, n[i])

proc partialMatch*(c: PContext, n, nOrig: PNode, m: var TCandidate) =
# for 'suggest' support:
var marker = initIntSet()
Expand Down
13 changes: 13 additions & 0 deletions tests/generics/t23186.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# issue #23186

template typedTempl(x: int, body): untyped =
body

proc generic1[T]() =
discard

proc generic2[T]() =
typedTempl(1):
let x = generic1[T]

generic2[int]()
2 changes: 1 addition & 1 deletion tests/generics/t6137.nim
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
discard """
errormsg: "\'vectFunc\' doesn't have a concrete type, due to unspecified generic parameters."
errormsg: "cannot instantiate: 'T'"
line: 28
"""

Expand Down

0 comments on commit 6b2f102

Please sign in to comment.