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

@ -210,7 +210,7 @@ proc semConstructFields(c: PContext, n: PNode,
localError(c.config, constrCtx.initExpr.info,
"a case selecting discriminator '$1' with value '$2' " &
"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])
template valuesInConflictError(valsDiff) =
@ -365,11 +365,10 @@ proc defaultConstructionError(c: PContext, t: PType, info: TLineInfo) =
assert constrCtx.missingFields.len > 0
localError(c.config, info,
"The $1 type doesn't have a default value. The following fields must " &
"be initialized: $2.",
[typeToString(t), listSymbolNames(constrCtx.missingFields)])
"be initialized: $2." % [typeToString(t), listSymbolNames(constrCtx.missingFields)])
elif objType.kind == tyDistinct:
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:
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
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})
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.
result.typ.flags.incl tfHasOwned
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
# 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:
hasError = true
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)])
# Since we were traversing the object fields, it's possible that