Skip to content

Wrong StructLayoutAttribute.Size for struct unions with no data fields #18125

@ghost

Description

Consider this type:

[<Struct>]
type ABC = A | B | C

F# 9 compiles it to a struct with this attribute (among others):

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto, Size = 1)]

However, because of the compiler-generated _tag field, the size is actually 4:

> sizeof<ABC>;;                                                        
val it: int = 4

This seems not to cause any problems, but the documentation states "This field must be equal or greater than the total size, in bytes, of the members of the class or structure," which suggests this should be corrected.

Metadata

Metadata

Assignees

Labels

Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendBugImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.good first issuehelp wanted

Type

No fields configured for Bug.

Projects

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions