Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR restricts typedesc field access on object/tuple types (e.g. Foo[int].val) so that it only works inside a typeof context. A new legacy switch --legacy:typedescFieldAccess restores the previous behavior. Existing tests and stdlib usages that relied on the old behavior are updated to wrap such accesses in typeof(...).
Changes:
- In
tryReadingTypeField, only resolve fields ontyObject/tyTupletypedescs when inside a typeof context or under the legacy flag. - Add the
typedescFieldAccesslegacy feature and document the breaking change inchangelog.md. - Update tests and
lib/pure/nimprof.nimto usetypeof(...), and add a regression test for the legacy flag.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| compiler/semexprs.nim | Gate object/tuple typedesc field access on inTypeofContext or the legacy feature. |
| compiler/options.nim | Add typedescFieldAccess to the legacy features enum. |
| changelog.md | Document the breaking change and how to opt out. |
| lib/pure/nimprof.nim | Wrap StackTrace.lines accesses in typeof(...) to keep working under the new rule. |
| tests/metatype/ttypedesc3.nim | Update to use typeof(Foo[int].val). |
| tests/metatype/ttypedesc_field_legacy.nim | New regression test for --legacy:typedescFieldAccess. |
| tests/concepts/tmapconcept.nim | Update SparseSeq.data access to use typeof(...). |
| tests/pragmas/tcustom_pragma.nim | Update Baz.x access to use typeof(...). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This pull request introduces a new restriction on typedesc field access for object and tuple types, limiting it to
typeofcontexts by default. It also adds a legacy compiler flag to restore the previous behavior, updates affected code and tests to comply with the new rule, and provides test coverage for the legacy mode.Language Semantics and Compiler Options:
Foo[int].val) is now only allowed in atypeofcontext. Use the new--legacy:typedescFieldAccessflag to restore the old behavior if needed. [1] [2] [3]Codebase and Test Adjustments:
nimprof.nim,tmapconcept.nim,ttypedesc3.nim, andtcustom_pragma.nimto usetypeofwhen accessing typedesc fields, ensuring compatibility with the new restriction. [1] [2] [3] [4] [5]ttypedesc_field_legacy.nim) to verify that the legacy flag (--legacy:typedescFieldAccess) restores the previous behavior, allowing typedesc field access outside oftypeof.