fixes #25784; Object default field initialized with an object constructor#25785
Open
fixes #25784; Object default field initialized with an object constructor#25785
Conversation
Contributor
There was a problem hiding this comment.
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
semObjConstrto allowtyForwardto pass duringefDetermineTypeanalysis (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.
Draft
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.
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:
semObjConstrincompiler/semobjconstr.nimto 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:
tests/objects/mobject_default_value.nimto verify that objects with default fields referencing forward types are correctly initialized, and that their default values are properly set.