Skip to content

Fix StructLayout Size for struct discriminated unions#19946

Open
KirtiRamchandani wants to merge 2 commits into
dotnet:mainfrom
KirtiRamchandani:fix/struct-union-layout-size-18125
Open

Fix StructLayout Size for struct discriminated unions#19946
KirtiRamchandani wants to merge 2 commits into
dotnet:mainfrom
KirtiRamchandani:fix/struct-union-layout-size-18125

Conversation

@KirtiRamchandani

Copy link
Copy Markdown

Fixes #18125

Struct unions get a compiler-generated _tag field but defaultLayout was still emitting StructLayout(..., Size = 1) when there are no declared instance fields.

This adds tycon.IsUnionTycon to the condition that omits an explicit size, matching what we already do for structs with instance fields.

Added StructUnionLayout18125.fs which checks sizeof<ABC> = 4 for a three-case struct DU.

Struct DUs carry a compiler-generated tag field but were emitted with
StructLayout Size=1 when they had no declared instance fields.

Fixes dotnet#18125
@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

❗ Release notes required

You can open this PR in browser to add release notes: open in github.dev


✅ Found changes and release notes in following paths:

Change path Release notes path Description
src/Compiler docs/release-notes/.FSharp.Compiler.Service/11.0.100.md

@github-actions github-actions Bot added the ⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen label Jun 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🔍 Tooling Safety Check — Affects-Compiler-Output
Affects-Compiler-Output: IlxGen.fs change alters StructLayout emission for struct unions

Generated by PR Tooling Safety Check · opus46 3M ·

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

⚠️ Affects-Compiler-Output Tooling check: PR touches IL emission or codegen

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

Wrong StructLayoutAttribute.Size for struct unions with no data fields

1 participant