Skip to content

fixes #25784; Object default field initialized with an object constructor#25785

Open
ringabout wants to merge 2 commits intodevelfrom
pr_obj_constr
Open

fixes #25784; Object default field initialized with an object constructor#25785
ringabout wants to merge 2 commits intodevelfrom
pr_obj_constr

Conversation

@ringabout
Copy link
Copy Markdown
Member

fixes #25784

This pull request addresses the handling of forward object types during type determination in the Nim compiler and adds new test cases to ensure correct default value initialization for objects with forward references. The main focus is to allow forward object types to remain unresolved during the initial type analysis, deferring their resolution to a later compilation phase. This helps support object constructors with default values involving forward types.

Compiler improvements:

  • Updated semObjConstr in compiler/semobjconstr.nim to allow forward object types (tyForward) to remain unresolved during determine-type analysis. This avoids premature errors and ensures that such types are resolved later, supporting delayed field-default resolution.

Testing enhancements:

  • Added new test cases in tests/objects/mobject_default_value.nim to verify that objects with default fields referencing forward types are correctly initialized, and that their default values are properly set.

Copilot AI review requested due to automatic review settings May 1, 2026 11:11
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 updates Nim’s object-constructor semantic checking to better handle forward-declared types during determine-type analysis, enabling default field values that reference objects declared later in the same type section (fixing #25784).

Changes:

  • Adjust semObjConstr to allow tyForward to pass during efDetermineType analysis (deferring resolution to the type section final pass).
  • Add regression tests ensuring default object field initialization works when the default uses a forward-declared object constructor.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
compiler/semobjconstr.nim Defers errors for forward object types during determine-type analysis to support delayed default-field resolution.
tests/objects/mobject_default_value.nim Adds regression coverage for default field values using object constructors with forward-declared object types.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/objects/mobject_default_value.nim Outdated
Comment thread compiler/semobjconstr.nim Outdated
Co-authored-by: Copilot <copilot@github.com>
@ringabout ringabout changed the title fixes #25784; Object field initialized with an object constructor fixes #25784; Object default field initialized with an object constructor May 1, 2026
@demotomohiro demotomohiro mentioned this pull request May 1, 2026
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.

Object field initialized with an object constructor that is declared later fail to compile

2 participants