Skip to content

Commit

Permalink
properly disallow unresolved generic proc values (#22005)
Browse files Browse the repository at this point in the history
* properly disallow unresolved generic proc values

* mirrors semoperand

* shallow efTypeAllowed, add back special case
  • Loading branch information
metagn committed Jun 5, 2023
1 parent c7c3362 commit 0a212f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
14 changes: 13 additions & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ proc ambiguousSymChoice(c: PContext, orig, n: PNode): PNode =
result = n

proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType: PType = nil): PNode =
result = semExprCheck(c, n, flags, expectedType)
result = semExprCheck(c, n, flags-{efTypeAllowed}, expectedType)
if result.typ == nil and efInTypeof in flags:
result.typ = c.voidType
elif (result.typ == nil or result.typ.kind == tyNone) and
Expand All @@ -130,6 +130,18 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}, expectedType
elif result.typ.kind == tyError:
# associates the type error to the current owner
result.typ = errorType(c)
elif efTypeAllowed in flags and result.typ.kind == tyProc and
hasUnresolvedParams(result, {}):
# mirrored with semOperand but only on efTypeAllowed
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)
result.typ = errorType(c)
else:
if result.typ.kind in {tyVar, tyLent}: result = newDeref(result)

Expand Down
1 change: 0 additions & 1 deletion compiler/semstmts.nim
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,6 @@ proc semVarOrLet(c: PContext, n: PNode, symkind: TSymKind): PNode =
if hasEmpty(typ):
localError(c.config, def.info, errCannotInferTypeOfTheLiteral % typ.kind.toHumanStr)
elif typ.kind == tyProc and def.kind == nkSym and isGenericRoutine(def.sym.ast):
# tfUnresolved in typ.flags:
let owner = typ.owner
let err =
# consistent error message with evaltempl/semMacroExpr
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
discard """
errormsg: "instantiate 'notConcrete' explicitly"
line: 12
disabled: "true"
"""

proc wrap[T]() =
proc notConcrete[T](x, y: int): int =
var dummy: T
result = x - y

var x: proc (x, y: T): int
x = notConcrete

x = notConcrete #[tt.Error
^ 'notConcrete' doesn't have a concrete type, due to unspecified generic parameters.]#

wrap[int]()

0 comments on commit 0a212f9

Please sign in to comment.