Repository navigation
Conversation
✅ Release notes checked
|
…] struct An inline-array struct declares a single field that the runtime replicates Length times, so its source-level field list is not its layout. Nothing in the compiler consulted InlineArrayAttribute, and the generated members enumerate declared fields only: values that differ in a replicated element compare equal, hash the same, and compare as 0. The runtime already refuses this shape - the default Equals and GetHashCode throw NotSupportedException for types marked with the attribute - so the compiler reports an error rather than silently generating members that ignore the replicas. 'NoEquality'/'NoComparison' and 'CustomEquality' stay valid, since they suppress generation. The check asks whether the members are actually generated, not whether the suppressing attributes are present: a field type without equality, or a byref-like struct, generates nothing and is left alone. Attribute lookup is name-based, as for IsByRefLikeAttribute. Fixes dotnet#21005.
Covers the error where members are generated (val-field and struct-record shapes), the shapes that suppress generation (NoEquality/NoComparison, CustomEquality), NoComparison alone (equality is still generated, so the error still applies), and the shapes that generate nothing at all: a field type without equality, a byref-like struct, and a signature-file declaration. A four-field struct is the control.
05a8a3b to
c8201d8
Compare
|
Thanks for the fix, @glyh. I built this PR's head (c8201d8) and tried it on the repro from #21005 and the cases I offered there. Your 9 tests pass here, and FS3926 fires on the issue's repro, on Two small things I noticed:
Outside this issue's scope: a C#-declared inline array without its own |
…ity' with 'NoComparison' The message told users to implement 'CustomEquality' and 'CustomComparison', but '[<CustomEquality; NoComparison>]' is equally valid - the compiler's own test uses it. Point at the two accepted combinations instead, matching the wording of FS0387.
The test claimed the error reports once, but its .fs was only 'module M', so the struct was declared in the .fsi alone and the name was untestable - withErrorCode only checks that the code appears at least once. The check runs per file, as the other augmentation checks do (an [<NoEquality>] without [<NoComparison>] gives FS0378 in each file), so declare the struct in both files and pin both diagnostics exactly via withDiagnostics.
|
Both done, thanks. The double report is expected — the check runs per file, same as the others (a stray Message reworded to On the C# case: I tried it, and it's .NET's own contract rather than a gap on our side. The runtime throws |
|
Thanks, @glyh. I re-tested at 1e01b80: your 9 tests pass, and the updated signature-file test also passes when run on its own. FS3926 still fires, now with the new wording, on the repro and on the other cases where it should. The Agreed on the C# case, and thanks for checking it. |
Description
Report FS3926 when structural members would be generated for a struct carrying
[<InlineArray(N)>]. The generated members enumerate declared fields, so the elements the runtime replicates are invisible to them:The runtime refuses this shape instead of comparing it:
ValueType.EqualsthrowsNotSupportedExceptionfor inline arrays (comutilnative.cpp#L1676, docs). F# suppresses that guard by generating its ownEquals, and generates the wrong one.The check asks whether members were actually generated, so shapes that generate nothing stay silent: a field type without equality, a byref-like struct,
[<NoEquality; NoComparison>],[<CustomEquality>].[<NoComparison>]alone still errors, since equality is still generated. Generation itself is unchanged — the check sits inCheckAugmentationAttribs.Escape hatches:
[<NoEquality; NoComparison>], or[<CustomEquality>]plus anEquals/GetHashCodecovering every element.Fixes #21005
Checklist
docs/release-notes/.FSharp.Compiler.Service/11.0.200.mdtests/FSharp.Compiler.ComponentTests/Diagnostics/InlineArray.fs— 9 cases: val-field struct, struct record,NoComparisonalone, signature file, plus the shapes that must stay silent.Open question: severity. An error matches the runtime's refusal; a warning plus a
LangVersiongate is the softer alternative.Written with LLM assistance, then reviewed and checked by hand: the repro, the runtime exception and the test runs above were all executed locally, and every claim in this description was verified against the code before opening.