Skip to content

Compiler: populate the aliased type when resolving through a typealias - #2495

Merged
bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/typealias-not-populated-for-sizeof
Sep 7, 2026
Merged

bfiete merged 1 commit into
beefytech:masterfrom
jayrulez:fix/typealias-not-populated-for-sizeof

Conversation

@jayrulez

@jayrulez jayrulez commented Sep 5, 2026

Copy link
Copy Markdown
Contributor

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.

    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.

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.

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
jayrulez force-pushed the fix/typealias-not-populated-for-sizeof branch from a914f95 to 8c683de Compare September 5, 2026 18:19
@bfiete

bfiete commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

Looks reasonable, and I appreciate a reasonable-looking test as well.

@bfiete
bfiete merged commit 00edb2f into beefytech:master Sep 7, 2026
7 checks passed
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.

2 participants