minor improvements of error messages of objvariants

This commit is contained in:
ringabout
2025-07-10 22:53:45 +08:00
parent 08642ffe34
commit 86f64e6b71
2 changed files with 17 additions and 1 deletions

View File

@@ -236,7 +236,7 @@ proc semConstructFields(c: PContext, n: PNode, constrCtx: var ObjConstrContext,
let prevFields = fieldsPresentInBranch(selectedBranch)
let currentFields = fieldsPresentInBranch(i)
localError(c.config, constrCtx.initExpr.info,
("The fields '$1' and '$2' cannot be initialized together, " &
("The fields $1 and $2 cannot be initialized together, " &
"because they are from conflicting branches in the case object.") %
[prevFields, currentFields])
result.status = initConflict

View File

@@ -0,0 +1,16 @@
discard """
errormsg: '''
The fields 'x' and 'y' cannot be initialized together, because they are from conflicting branches in the case object.
'''
"""
type
Foo = object
case kind: bool
of true:
x: int
of false:
y: int
var f = Foo(x: 1, y: 1)