mirror of
https://github.com/nim-lang/Nim.git
synced 2026-08-28 01:21:40 +00:00
adds legacy:typedescFieldAccess
This commit is contained in:
@@ -12,6 +12,10 @@ rounding guarantees (via the
|
||||
avoid conflicts with `system.default`, so named argument usage for this
|
||||
parameter like `getOrDefault(..., default = ...)` will have to be changed.
|
||||
|
||||
- Typedesc field access on object/tuple types (e.g. `Foo[int].val`) is now
|
||||
restricted to `typeof` context. Use `--legacy:typedescFieldAccess` to restore
|
||||
the previous behavior of allowing it outside `typeof`.
|
||||
|
||||
- With `-d:nimPreviewCheckedClose`, the `close` function in the `std/syncio` module now raises an IO exception in case of an error.
|
||||
|
||||
- Unknown warnings and hints now gives warnings `warnUnknownNotes` instead of
|
||||
|
||||
@@ -262,6 +262,9 @@ type
|
||||
procParamTypeBackendAliases
|
||||
## Keep the old proc type compatibility rules that ignore backend
|
||||
## c type aliases.
|
||||
typedescFieldAccess
|
||||
## Allow typedesc field access on object/tuple types outside of
|
||||
## typeof context.
|
||||
|
||||
SymbolFilesOption* = enum
|
||||
disabledSf, writeOnlySf, readOnlySf, v2Sf, stressTest
|
||||
|
||||
@@ -1500,7 +1500,7 @@ proc tryReadingTypeField(c: PContext, n: PNode, i: PIdent, ty: PType): PNode =
|
||||
markUsed(c, n.info, f)
|
||||
onUse(n.info, f)
|
||||
of tyObject, tyTuple:
|
||||
if c.inTypeofContext > 0 and
|
||||
if (c.inTypeofContext > 0 or typedescFieldAccess in c.config.legacyFeatures) and
|
||||
ty.n != nil and ty.n.kind == nkRecList:
|
||||
let field = lookupInRecord(ty.n, i)
|
||||
if field != nil:
|
||||
|
||||
11
tests/metatype/ttypedesc_field_legacy.nim
Normal file
11
tests/metatype/ttypedesc_field_legacy.nim
Normal file
@@ -0,0 +1,11 @@
|
||||
discard """
|
||||
matrix: "--legacy:typedescFieldAccess"
|
||||
output: "4"
|
||||
"""
|
||||
|
||||
type
|
||||
Foo[T] = object
|
||||
val: T
|
||||
|
||||
var x: Foo[int].val = 4
|
||||
echo x
|
||||
Reference in New Issue
Block a user