Repository navigation
Conversation
hvitved
force-pushed
the
unified/type-inference-constructors
branch
2 times, most recently
from
October 10, 2026 07:22
e5f4c43 to
909aa94
Compare
hvitved
force-pushed
the
unified/type-inference-constructors
branch
from
October 19, 2026 07:54
8102a8e to
80c4bfb
Compare
hvitved
force-pushed
the
unified/type-inference-constructors
branch
3 times, most recently
from
October 19, 2026 19:51
7a3d1be to
1c20541
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Constructor inference loses contextual argument types and can produce incorrect inherited type mappings and superclass results.
4 open issues
What changed in this PR
Improves constructor-call type inference in Unified, particularly for inherited Swift initializers.
Changes:
- Models constructors using receiver types.
- Extends shared contextual inference support.
- Adds inherited-constructor tests and updates expectations.
| File | Description |
|---|---|
| unified/ql/test/library-tests/type-inference/type-inference.expected | Updates generated inference expectations. |
| unified/ql/test/library-tests/type-inference/lub.swift | Updates an inline expected initializer target. |
| unified/ql/test/library-tests/type-inference/constructors.swift | Adds inherited and generic constructor cases. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeMention.qll | Excludes enum cases from resolved types. |
| unified/ql/lib/codeql/unified/internal/typeinference/TypeInference.qll | Adds receiver-based constructor inference. |
| unified/ql/lib/codeql/unified/internal/ExprPositions.qll | Excludes enum cases from type contexts. |
| shared/typeinference/codeql/typeinference/internal/TypeInference.qll | Extracts reusable contextual typing logic and adds an inference hook. |
Review effort: Max
hvitved
force-pushed
the
unified/type-inference-constructors
branch
from
October 20, 2026 09:03
1c20541 to
b3e63f8
Compare
Contributor
There was a problem hiding this comment.
🟡 Changes recommended
Unresolved type-resolution and contextual-inference defects affect correctness.
5 open issues
Preserve enum type for unqualified enum-case construction · New Infer contextual holes from constructed receiver types · New Recognize enum constructors in generic contextual inference · New Resolve associated-type variants by accessing class · New Swap incorrect initializer annotation targets · New
4 resolved since last review
Review effort: Max
hvitved
force-pushed
the
unified/type-inference-constructors
branch
from
October 20, 2026 11:51
b3e63f8 to
a5037ad
Compare
hvitved
force-pushed
the
unified/type-inference-constructors
branch
from
October 20, 2026 12:34
a5037ad to
4898fef
Compare
hvitved
marked this pull request as ready for review
October 20, 2026 18:18
This branch has not been deployed
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 PR starts treating constructors like ordinary instance methods without return types, in order to be able to handle inheritance in the same was as for ordinary methods.
Because the constructor calls are treated as normal instance method calls, we use the type qualifier to represent the receiver, and then allow for contextual type information to flow into the receiver:
A,Tais inferred to be instantiated toInt, which is propagated directly back into the receiver.B,Tais inferred to be instantiated toInt?which in turn meansTbis inferred to be instantiated toInt, which is then propagated back into the receiver.B<Int>, and no further type inference is needed.DCA shows a small increase in resolution rates.
Commit-by-commit review is encouraged (third commit is best reviewed ignoring whitespace changes).