Compiler: populate the aliased type when resolving through a typealias - #2495
Merged
bfiete merged 1 commit intoSep 7, 2026
Merged
Conversation
ResolveTypeResult walks a chain of aliases, populating each alias and then
stepping to what it refers to, but never applies the caller's requested
populate level to the type it ends up returning. The unpopulated defaults are
0 for size and 1 for align, so the result is a silently wrong constant rather
than an error.
struct S { public float a; public float b; }
typealias A = S;
sizeof(A) // 0, want 8
alignof(A) // 1, want 4
Affected, all silent: sizeof, alignof and strideof through an alias, through
an alias chain, to a generic instantiation, to an alias declared inside a
class, to an enum, to a tuple, to a type in another namespace, and the same
read from a const initializer or a comptime block.
Not affected, because these reach the type through paths that populate it
anyway: offsetof, a field or sized-array field typed by the alias, sizeof of
an array of the alias, a generic parameterised by the alias, and
typeof(alias).Size and .InstanceSize.
Adds Aliases.TestAliasedTypeAttrs over a plain struct, an alias chain and a
struct whose body is emitted at comptime, none of them referenced elsewhere so
incidental population cannot mask a regression.
jayrulez
force-pushed
the
fix/typealias-not-populated-for-sizeof
branch
from
September 5, 2026 18:19
a914f95 to
8c683de
Compare
Collaborator
|
Looks reasonable, and I appreciate a reasonable-looking test as well. |
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.
ResolveTypeResult walks a chain of aliases, populating each alias and then stepping to what it refers to, but does not apply the caller's requested populate level to the type it ends up returning. The unpopulated defaults are 0 for size and 1 for align, so the result is a silently wrong constant instead of an error.
Affected, all silent: sizeof, alignof and strideof through an alias, through an alias chain, to a generic instantiation, to an alias declared inside a class, to an enum, to a tuple, to a type in another namespace, and the same read from a const initializer or a comptime block.
Not affected, because these reach the type through paths that populate it anyway: offsetof, a field or sized-array field typed by the alias, sizeof of an array of the alias, a generic parameterised by the alias, and typeof(alias).Size and .InstanceSize.
Add Aliases.TestAliasedTypeAttrs over a plain struct, an alias chain and a struct whose body is emitted at comptime.
Note: This was debugged by and the fix suggested by Claude.