Skip to content

fix typedesc field access#25811

Open
ringabout wants to merge 3 commits into
develfrom
pr_field
Open

fix typedesc field access#25811
ringabout wants to merge 3 commits into
develfrom
pr_field

Conversation

@ringabout
Copy link
Copy Markdown
Member

@ringabout ringabout commented May 13, 2026

This pull request introduces a new restriction on typedesc field access for object and tuple types, limiting it to typeof contexts 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:

  • Typedesc field access on object/tuple types (e.g., Foo[int].val) is now only allowed in a typeof context. Use the new --legacy:typedescFieldAccess flag to restore the old behavior if needed. [1] [2] [3]

Codebase and Test Adjustments:

  • Updated code in nimprof.nim, tmapconcept.nim, ttypedesc3.nim, and tcustom_pragma.nim to use typeof when accessing typedesc fields, ensuring compatibility with the new restriction. [1] [2] [3] [4] [5]
  • Added a new test (ttypedesc_field_legacy.nim) to verify that the legacy flag (--legacy:typedescFieldAccess) restores the previous behavior, allowing typedesc field access outside of typeof.

@ringabout ringabout changed the title test typedesc field access fix typedesc field access May 15, 2026
@ringabout ringabout marked this pull request as ready for review May 15, 2026 12:39
Copilot AI review requested due to automatic review settings May 15, 2026 12:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on tyObject/tyTuple typedescs when inside a typeof context or under the legacy flag.
  • Add the typedescFieldAccess legacy feature and document the breaking change in changelog.md.
  • Update tests and lib/pure/nimprof.nim to use typeof(...), 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants