fix hintMsgOrigin regression + simplify msgs code (#17805)

This commit is contained in:
Timothee Cour 2021-04-20 22:00:45 -07:00 • committed by GitHub
commit 8de053d870
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 22 additions and 32 deletions

View file

@ -14,7 +14,7 @@ import std/private/miscdollars
import strutils2 import strutils2
type InstantiationInfo* = typeof(instantiationInfo()) type InstantiationInfo* = typeof(instantiationInfo())
template instLoc(): InstantiationInfo = instantiationInfo(-2, fullPaths = true) template instLoc*(): InstantiationInfo = instantiationInfo(-2, fullPaths = true)
template toStdOrrKind(stdOrr): untyped = template toStdOrrKind(stdOrr): untyped =
if stdOrr == stdout: stdOrrStdout else: stdOrrStderr if stdOrr == stdout: stdOrrStdout else: stdOrrStderr
@ -600,9 +600,6 @@ template localError*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "")
template localError*(conf: ConfigRef; info: TLineInfo, arg: string) = template localError*(conf: ConfigRef; info: TLineInfo, arg: string) =
liMessage(conf, info, errGenerated, arg, doNothing, instLoc()) liMessage(conf, info, errGenerated, arg, doNothing, instLoc())
template localError*(conf: ConfigRef; info: TLineInfo, format: string, params: openArray[string]) =
liMessage(conf, info, errGenerated, format % params, doNothing, instLoc())
template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") = template message*(conf: ConfigRef; info: TLineInfo, msg: TMsgKind, arg = "") =
liMessage(conf, info, msg, arg, doNothing, instLoc()) liMessage(conf, info, msg, arg, doNothing, instLoc())

View file

@ -501,18 +501,14 @@ proc errorNode*(c: PContext, n: PNode): PNode =
result = newNodeI(nkEmpty, n.info) result = newNodeI(nkEmpty, n.info)
result.typ = errorType(c) result.typ = errorType(c)
proc localErrorNode*(c: PContext, n: PNode, info: TLineInfo, msg: TMsgKind, arg: string): PNode = template localErrorNode*(c: PContext, n: PNode, arg: string, info: TLineInfo, kind: TMsgKind = errGenerated): PNode =
localError(c.config, info, msg, arg) liMessage(c.config, info, kind, arg, doNothing, instLoc())
result = errorNode(c, n) errorNode(c, n)
proc localErrorNode*(c: PContext, n: PNode, info: TLineInfo, arg: string): PNode = template localErrorNode*(c: PContext, n: PNode, arg: string, kind: TMsgKind = errGenerated): PNode =
localErrorNode(c, n, info, errGenerated, arg) let n2 = n
liMessage(c.config, n2.info, kind, arg, doNothing, instLoc())
proc localErrorNode*(c: PContext, n: PNode, msg: TMsgKind, arg: string): PNode = errorNode(c, n2)
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) = proc fillTypeS*(dest: PType, kind: TTypeKind, c: PContext) =
dest.kind = kind dest.kind = kind

View file

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

View file

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

View file

@ -210,7 +210,7 @@ proc semConstructFields(c: PContext, n: PNode,
localError(c.config, constrCtx.initExpr.info, localError(c.config, constrCtx.initExpr.info,
"a case selecting discriminator '$1' with value '$2' " & "a case selecting discriminator '$1' with value '$2' " &
"appears in the object construction, but the field(s) $3 " & "appears in the object construction, but the field(s) $3 " &
"are in conflict with this value.", "are in conflict with this value." %
[discriminator.sym.name.s, discriminatorVal.renderTree, fields]) [discriminator.sym.name.s, discriminatorVal.renderTree, fields])
template valuesInConflictError(valsDiff) = template valuesInConflictError(valsDiff) =
@ -365,11 +365,10 @@ proc defaultConstructionError(c: PContext, t: PType, info: TLineInfo) =
assert constrCtx.missingFields.len > 0 assert constrCtx.missingFields.len > 0
localError(c.config, info, localError(c.config, info,
"The $1 type doesn't have a default value. The following fields must " & "The $1 type doesn't have a default value. The following fields must " &
"be initialized: $2.", "be initialized: $2." % [typeToString(t), listSymbolNames(constrCtx.missingFields)])
[typeToString(t), listSymbolNames(constrCtx.missingFields)])
elif objType.kind == tyDistinct: elif objType.kind == tyDistinct:
localError(c.config, info, localError(c.config, info,
"The $1 distinct type doesn't have a default value.", [typeToString(t)]) "The $1 distinct type doesn't have a default value." % typeToString(t))
else: else:
assert false, "Must not enter here." assert false, "Must not enter here."
@ -379,7 +378,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
for child in n: result.add child for child in n: result.add child
if t == nil: if t == nil:
return localErrorNode(c, result, errGenerated, "object constructor needs an object type") return localErrorNode(c, result, "object constructor needs an object type")
t = skipTypes(t, {tyGenericInst, tyAlias, tySink, tyOwned}) t = skipTypes(t, {tyGenericInst, tyAlias, tySink, tyOwned})
if t.kind == tyRef: if t.kind == tyRef:
@ -390,7 +389,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
# multiple times as long as they don't have closures. # multiple times as long as they don't have closures.
result.typ.flags.incl tfHasOwned result.typ.flags.incl tfHasOwned
if t.kind != tyObject: if t.kind != tyObject:
return localErrorNode(c, result, errGenerated, "object constructor needs an object type") return localErrorNode(c, result, "object constructor needs an object type")
# Check if the object is fully initialized by recursively testing each # Check if the object is fully initialized by recursively testing each
# field (if this is a case object, initialized fields in two different # field (if this is a case object, initialized fields in two different
@ -404,7 +403,7 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode =
if constrCtx.missingFields.len > 0: if constrCtx.missingFields.len > 0:
hasError = true hasError = true
localError(c.config, result.info, localError(c.config, result.info,
"The $1 type requires the following fields to be initialized: $2.", "The $1 type requires the following fields to be initialized: $2." %
[t.sym.name.s, listSymbolNames(constrCtx.missingFields)]) [t.sym.name.s, listSymbolNames(constrCtx.missingFields)])
# Since we were traversing the object fields, it's possible that # Since we were traversing the object fields, it's possible that

View file

@ -725,7 +725,7 @@ proc semForVars(c: PContext, n: PNode; flags: TExprFlags): PNode =
if n.len == 3: if n.len == 3:
if n[0].kind == nkVarTuple: if n[0].kind == nkVarTuple:
if n[0].len-1 != iterAfterVarLent.len: if n[0].len-1 != iterAfterVarLent.len:
return localErrorNode(c, n, n[0].info, errWrongNumberOfVariables) return localErrorNode(c, n, errWrongNumberOfVariables, n[0].info)
for i in 0..<n[0].len-1: for i in 0..<n[0].len-1:
var v = symForVar(c, n[0][i]) var v = symForVar(c, n[0][i])
@ -1024,8 +1024,7 @@ proc semRaise(c: PContext, n: PNode): PNode =
if typ.kind != tyRef: if typ.kind != tyRef:
localError(c.config, n.info, errExprCannotBeRaised) localError(c.config, n.info, errExprCannotBeRaised)
if typ.len > 0 and not isException(typ.lastSon): if typ.len > 0 and not isException(typ.lastSon):
localError(c.config, n.info, "raised object of type $1 does not inherit from Exception", localError(c.config, n.info, "raised object of type $1 does not inherit from Exception" % typeToString(typ))
[typeToString(typ)])
proc addGenericParamListToScope(c: PContext, n: PNode) = proc addGenericParamListToScope(c: PContext, n: PNode) =
if n.kind != nkGenericParams: illFormedAst(n, c.config) if n.kind != nkGenericParams: illFormedAst(n, c.config)
@ -2201,8 +2200,7 @@ proc inferConceptStaticParam(c: PContext, inferred, n: PNode) =
if not sameType(res.typ, typ.base): if not sameType(res.typ, typ.base):
localError(c.config, n.info, localError(c.config, n.info,
"cannot infer the concept parameter '%s', due to a type mismatch. " & "cannot infer the concept parameter '%s', due to a type mismatch. " &
"attempt to equate '%s' and '%s'.", "attempt to equate '%s' and '%s'." % [inferred.renderTree, $res.typ, $typ.base])
[inferred.renderTree, $res.typ, $typ.base])
typ.n = res typ.n = res
proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode = proc semStmtList(c: PContext, n: PNode, flags: TExprFlags): PNode =