mirror of
https://github.com/nim-lang/Nim.git
synced 2026-06-15 08:03:46 +00:00
fixes #22791
This pull request introduces a minor improvement to the handling of
immutable variables in the compiler and adds a new test case for nested
case objects. The most important changes are:
### Compiler improvements
* Updated the `isLet` guard in `compiler/guards.nim` to recognize
`skConst` symbols as immutable variables, ensuring that constants are
correctly identified alongside lets and other immutable types.
### Test coverage
* Added a new test in `tests/objvariant/tcorrectcheckedfield.nim` for
bug #22791, verifying correct pattern matching and field access in
nested `case` objects with constants.
(cherry picked from commit 3e2cea21ed)
44 lines
727 B
Nim
44 lines
727 B
Nim
discard """
|
|
matrix: "; --warning[ProveField]:on --warningAsError[ProveField]:on; --experimental:strictCaseObjects"
|
|
"""
|
|
|
|
block: # issue #24021
|
|
type
|
|
FooKind = enum
|
|
a
|
|
b
|
|
BiggerEnum = enum b1, b2, b3, b4, b5, b6, b7, b8, b9, b10
|
|
Foo = object
|
|
case kind: FooKind
|
|
of a: discard
|
|
else:
|
|
z: BiggerEnum
|
|
|
|
proc p(foo: Foo, val: int) =
|
|
case foo.kind
|
|
of a:
|
|
discard
|
|
else:
|
|
discard foo.z
|
|
|
|
|
|
# bug #22791
|
|
type Foo = object
|
|
case a: bool
|
|
of false:
|
|
discard
|
|
of true:
|
|
case b: bool
|
|
of false:
|
|
discard
|
|
of true:
|
|
c: bool
|
|
|
|
const f = Foo(a: true, b: true, c: true)
|
|
case f.a
|
|
of true:
|
|
case f.b
|
|
of true:
|
|
echo f.c
|
|
else: discard
|
|
else: discard |