fix #19266; allow reassign discriminant field (#19567)

* add inUncheckedAssignSection

* add one more test
This commit is contained in:
flywind 2022-02-26 03:33:28 +08:00 • committed by GitHub
commit 9c17a32e0e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 2 deletions

View file

@ -34,3 +34,25 @@ proc passToVar(x: var Token) = discard
t.curr = TokenObject(kind: t.curr.kind, foo: "abc")
t.curr.kind = Token.foo
block:
type
TokenKind = enum
strLit, intLit
Token = object
case kind*: TokenKind
of strLit:
s*: string
of intLit:
i*: int64
var t = Token(kind: strLit, s: "abc")
{.cast(uncheckedAssign).}:
# inside the 'cast' section it is allowed to assign to the 't.kind' field directly:
t.kind = intLit
{.cast(uncheckedAssign).}:
t.kind = strLit