feat(cl): add infrastructure for deferred type variables (#2467) #2468
+76
−0
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.
Summary
Implements the foundational infrastructure for deferred type variables as described in issue #2467.
This PR adds the core data structures and tracking mechanisms needed to support deferred type inference, where variables with untyped literals remain unresolved until their first use.
Changes
Core Infrastructure
deferredVar structure (cl/compile.go:364-368): Tracks variables awaiting type resolution
blockCtx extension (cl/compile.go:430): Added
deferredVars map[string]*deferredVar
fieldHelper Functions (cl/compile.go:370-404)
isUntypedLiteral()
: Detects untyped literal expressions (BasicLit, empty SliceLit, empty map CompositeLit)addDeferredVar()
: Adds variable to deferred resolution queueresolveDeferredVar()
: Placeholder for future type resolution logicVariable Loading (cl/compile.go:1699-1755)
loadVars()
to detect single-variable declarations with untyped literalsTest Cases
cl/_testgop/deferred-int/
: Tests basic integer literal deferred inference ✅cl/_testgop/deferred-slice/
: Tests empty slice - infrastructure ready for resolution logicTest Results
The
deferred-int
test passes, confirming the infrastructure correctly tracks deferred variables. Thedeferred-slice
test reveals that the type resolution mechanism (step 2) is needed to properly infer[]int
from usage context.Scope & Next Steps
This PR focuses on infrastructure only as specified in the issue requirements:
Not included (for future PRs):
x <- 100
→[]int
)Related
🤖 Generated with codeagent