properly disallow unresolved generic proc values (#22005)

* properly disallow unresolved generic proc values

* mirrors semoperand

* shallow efTypeAllowed, add back special case
This commit is contained in:
metagn
2023-06-05 11:53:40 +03:00
committed by GitHub
parent c7c3362cc8
commit 0a212f97a5
3 changed files with 15 additions and 10 deletions

View File

@@ -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
@@ -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)

View File

@@ -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

View File

@@ -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]()