Introduce localErrorNode (#17785)

This commit is contained in:
Clyybber
2021-04-19 17:19:21 +02:00
committed by GitHub
parent 6de5aa1971
commit 438afb4db9
7 changed files with 27 additions and 24 deletions

View File

@@ -296,8 +296,7 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode =
result = evaluated
let expectedType = eOrig.typ.skipTypes({tyStatic})
if hasCycle(result):
globalError(c.config, eOrig.info, "the resulting AST is cyclic and cannot be processed further")
result = errorNode(c, eOrig)
result = localErrorNode(c, eOrig, "the resulting AST is cyclic and cannot be processed further")
else:
semmacrosanity.annotateType(result, expectedType, c.config)
else:

View File

@@ -501,6 +501,19 @@ proc errorNode*(c: PContext, n: PNode): PNode =
result = newNodeI(nkEmpty, n.info)
result.typ = errorType(c)
proc localErrorNode*(c: PContext, n: PNode, info: TLineInfo, msg: TMsgKind, arg: string): PNode =
localError(c.config, info, msg, arg)
result = errorNode(c, n)
proc localErrorNode*(c: PContext, n: PNode, info: TLineInfo, arg: string): PNode =
localErrorNode(c, n, info, errGenerated, arg)
proc localErrorNode*(c: PContext, n: PNode, msg: TMsgKind, arg: string): PNode =
localErrorNode(c, n, n.info, msg, arg)
proc localErrorNode*(c: PContext, n: PNode, arg: string): PNode =
localErrorNode(c, n, n.info, errGenerated, arg)
proc fillTypeS*(dest: PType, kind: TTypeKind, c: PContext) =
dest.kind = kind
dest.owner = getCurrOwner(c)

View File

@@ -1044,8 +1044,7 @@ proc buildEchoStmt(c: PContext, n: PNode): PNode =
if e != nil:
result.add(newSymNode(e))
else:
localError(c.config, n.info, "system needs: echo")
result.add(errorNode(c, n))
result.add localErrorNode(c, n, "system needs: echo")
result.add(n)
result = semExpr(c, result)
@@ -2621,8 +2620,7 @@ proc semTupleConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
# check if either everything or nothing is tyTypeDesc
for i in 1..<tupexp.len:
if isTupleType != (tupexp[i].typ.kind == tyTypeDesc):
localError(c.config, tupexp[i].info, "Mixing types and values in tuples is not allowed.")
return(errorNode(c,n))
return localErrorNode(c, n, tupexp[i].info, "Mixing types and values in tuples is not allowed.")
if isTupleType: # expressions as ``(int, string)`` are reinterpret as type expressions
result = n
var typ = semTypeNode(c, n, nil).skipTypes({tyTypeDesc})

View File

@@ -229,14 +229,12 @@ proc semBindSym(c: PContext, n: PNode): PNode =
let sl = semConstExpr(c, n[1])
if sl.kind notin {nkStrLit, nkRStrLit, nkTripleStrLit}:
localError(c.config, n[1].info, errStringLiteralExpected)
return errorNode(c, n)
return localErrorNode(c, n, n[1].info, errStringLiteralExpected)
let isMixin = semConstExpr(c, n[2])
if isMixin.kind != nkIntLit or isMixin.intVal < 0 or
isMixin.intVal > high(TSymChoiceRule).int:
localError(c.config, n[2].info, errConstExprExpected)
return errorNode(c, n)
return localErrorNode(c, n, n[2].info, errConstExprExpected)
let id = newIdentNode(getIdent(c.cache, sl.strVal), n.info)
let s = qualifiedLookUp(c, id, {checkUndeclared})
@@ -253,12 +251,10 @@ proc semBindSym(c: PContext, n: PNode): PNode =
proc opBindSym(c: PContext, scope: PScope, n: PNode, isMixin: int, info: PNode): PNode =
if n.kind notin {nkStrLit, nkRStrLit, nkTripleStrLit, nkIdent}:
localError(c.config, info.info, errStringOrIdentNodeExpected)
return errorNode(c, n)
return localErrorNode(c, n, info.info, errStringOrIdentNodeExpected)
if isMixin < 0 or isMixin > high(TSymChoiceRule).int:
localError(c.config, info.info, errConstExprExpected)
return errorNode(c, n)
return localErrorNode(c, n, info.info, errConstExprExpected)
let id = if n.kind == nkIdent: n
else: newIdentNode(getIdent(c.cache, n.strVal), info.info)

View File

@@ -379,8 +379,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
for child in n: result.add child
if t == nil:
localError(c.config, n.info, errGenerated, "object constructor needs an object type")
return errorNode(c, result)
return localErrorNode(c, result, errGenerated, "object constructor needs an object type")
t = skipTypes(t, {tyGenericInst, tyAlias, tySink, tyOwned})
if t.kind == tyRef:
@@ -391,8 +390,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
# multiple times as long as they don't have closures.
result.typ.flags.incl tfHasOwned
if t.kind != tyObject:
localError(c.config, n.info, errGenerated, "object constructor needs an object type")
return errorNode(c, result)
return localErrorNode(c, result, errGenerated, "object constructor needs an object type")
# Check if the object is fully initialized by recursively testing each
# field (if this is a case object, initialized fields in two different

View File

@@ -725,8 +725,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
if n.len == 3:
if n[0].kind == nkVarTuple:
if n[0].len-1 != iterAfterVarLent.len:
localError(c.config, n[0].info, errWrongNumberOfVariables)
return errorNode(c, n)
return localErrorNode(c, n, n[0].info, errWrongNumberOfVariables)
for i in 0..<n[0].len-1:
var v = symForVar(c, n[0][i])

View File

@@ -2269,10 +2269,10 @@ iterator genericParamsInMacroCall*(macroSym: PSym, call: PNode): (PSym, PNode) =
# to prevent endless recursion in macro instantiation
const evalMacroLimit = 1000
proc errorNode(idgen: IdGenerator; owner: PSym, n: PNode): PNode =
result = newNodeI(nkEmpty, n.info)
result.typ = newType(tyError, nextTypeId idgen, owner)
result.typ.flags.incl tfCheckedForDestructor
#proc errorNode(idgen: IdGenerator; owner: PSym, n: PNode): PNode =
# result = newNodeI(nkEmpty, n.info)
# result.typ = newType(tyError, nextTypeId idgen, owner)
# result.typ.flags.incl tfCheckedForDestructor
proc evalMacroCall*(module: PSym; idgen: IdGenerator; g: ModuleGraph; templInstCounter: ref int;
n, nOrig: PNode, sym: PSym): PNode =