You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
uncheckedAssign works with tests\objvariant\treassign.nim but failed with example from manual.rst
Both examples compiled successfully, but the later one throw unhandled exception during runtime.
The difference of the two is treassign.nim using child object, while example from manual.rst using top level object.
Example from manual.rst
typeTokenKind*=enum
strLit, intLit
Token=objectcase kind*: TokenKind of strLit:
s*: string of intLit:
i*: int64procpassToVar(x: varTokenKind) =discardvar t =Token(kind: strLit, s: "abc")
{.cast(uncheckedAssign).}:
# inside the 'cast' section it is allowed to pass 't.kind' to a 'var T' parameter:passToVar(t.kind)
# inside the 'cast' section it is allowed to set field 's' even though the# constructed 'kind' field has an unknown value:
t =Token(kind: t.kind, s: "abc")
# inside the 'cast' section it is allowed to assign to the 't.kind' field directly:
t.kind = intLit
Current Output
Compile with
$> nim c -r uc
F:\projects\bug\uc.nim(24) uc
F:\projects\nim\lib\system\assign.nim(296) FieldDiscriminantCheck
F:\projects\nim\lib\system\fatal.nim(53) sysFatal
Error: unhandled exception: assignment to discriminant changes object branch; compile with -d:nimOldCaseObjects for a transition period [FieldDefect]
Error: execution of an external program failed: 'F:\projects\bug\uc.exe '
Expected Output
no error/exception
$ nim -v
Nim Compiler Version 1.7.1 [Windows: amd64]
Compiled at 2022-02-10
Copyright (c) 2006-2022 by Andreas Rumpf
git hash: 27e548140b0f51a8dbc6f6094764e02f08ae509e
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
uncheckedAssign
works withtests\objvariant\treassign.nim
but failed with example frommanual.rst
Both examples compiled successfully, but the later one throw unhandled exception during runtime.
The difference of the two is
treassign.nim
using child object, while example frommanual.rst
using top level object.Example from manual.rst
Current Output
Compile with
$> nim c -r uc
Expected Output
The text was updated successfully, but these errors were encountered: