Skip to content

Add regression test: #12796, DefaultValue null on array type record field#19472

Open
T-Gro wants to merge 7 commits intomainfrom
regression-test/issue12796
Open

Add regression test: #12796, DefaultValue null on array type record field#19472
T-Gro wants to merge 7 commits intomainfrom
regression-test/issue12796

Conversation

@T-Gro
Copy link
Copy Markdown
Member

@T-Gro T-Gro commented Mar 24, 2026

Fixes #12796

Adds a regression test verifying that [<DefaultValue(null)>] on a record field of type A[] compiles successfully without internal error FS0192.

@T-Gro T-Gro requested a review from a team as a code owner March 24, 2026 10:33
@T-Gro T-Gro added NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes AI-Issue-Regression-PR PR adding regression test for a closed issue labels Mar 24, 2026
@T-Gro T-Gro requested a review from abonie March 24, 2026 10:33
@T-Gro T-Gro enabled auto-merge (squash) March 24, 2026 10:34
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Mar 24, 2026

⚠️ Release notes required, but author opted out

Warning

Author opted out of release notes, check is disabled for this pull request.
cc @dotnet/fsharp-team-msft

open System.ComponentModel

type A = { AField: string }
type B = { [<DefaultValue(null)>] BField: A[] }
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Big NO, the issue really says:

[<DefaultValue([||] : A[])>]

@github-actions
Copy link
Copy Markdown
Contributor

Commit pushed: 6d1be63

Generated by Regression PR Shepherd

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown
Contributor

Commit pushed: 7128e25

Generated by Regression PR Shepherd

@github-actions
Copy link
Copy Markdown
Contributor

🤖 This is an automated response from Regression PR Shepherd.

This regression test proves the bug in #12796 still exists on Desktop .NET Framework. Closing this PR is recommended.

The bug: [<DefaultValue([||] : A[])>] on a record field of type A[] triggers an internal compiler error FS0192: encodeCustomAttrElemType: unrecognized custom element type. The issue was opened in 2022, and was labeled AI-thinks-issue-fixed after the bot detected SynPat.Record and SynPat.QuoteExpr fixes — but that was a different issue; this bug is specifically about attribute encoding for array-typed DefaultValue arguments.

The test: tests/FSharp.Compiler.ComponentTests/Language/AttributeCheckingTests.fs typechecks type B = { [<DefaultValue([||] : A[])>] BField: A[] } and expects success.

The failure: Build WindowsNoRealsig_testDesktop fails — the test fails only on Desktop .NET Framework, not on CoreCLR/Linux. The FS0192 error is triggered during attribute argument encoding, which happens during type checking on Desktop.

The AI-thinks-issue-fixed label has been removed from #12796.

cc @T-Gro @abonie

Generated by Regression PR Shepherd ·

@T-Gro T-Gro force-pushed the regression-test/issue12796 branch 2 times, most recently from f367e8f to 254f0a8 Compare April 9, 2026 11:30
T-Gro and others added 6 commits April 10, 2026 11:45
…d field

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Per reviewer feedback, use the exact syntax from the issue report:
[<DefaultValue([||] : A[])>] rather than [<DefaultValue(null)>].
The empty-array-cast form is the specific repro that triggered the
'encodeCustomAttrElemType: unrecognized custom element type' error.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The internal error FS0192 is caught during type-checking; using
typecheck is sufficient and faster than a full compile.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
The test for [<DefaultValue([||] : A[])>] triggers FS0192 internal error
in encodeCustomAttrElemType on Desktop .NET Framework during attribute
encoding. The bug is fixed on CoreCLR only. Use FactForNETCOREAPP to
skip the test on Desktop where the bug still exists.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…ent types

Replace FS0192 internal error (encodeCustomAttrElemType crash) with a proper
user-facing diagnostic (FS3885) when a custom attribute array argument has an
element type that cannot be encoded in CLI metadata per ECMA 335.

Only primitive types, enums, string, System.Type, and System.Object are valid
element types for arrays in custom attributes. User-defined types like records
or classes now produce a clear error instead of an internal compiler crash.

The validation is added in GenAttribArg (IlxGen.fs) before the attribute
encoding layer is reached, so the error is caught early with proper source
location information.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro force-pushed the regression-test/issue12796 branch from c9f9eb2 to 929e77c Compare April 10, 2026 09:46
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro
Copy link
Copy Markdown
Member Author

T-Gro commented Apr 10, 2026

I don't get why we would have problems encoding empty arrays of any type? It does not matter if we cannot store instances of that type, since it is empty. If we can store a string array, an empty string array, why also not an arbitrary empty array?

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

Labels

AI-Issue-Regression-PR PR adding regression test for a closed issue NO_RELEASE_NOTES Label for pull requests which signals, that user opted-out of providing release notes

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

internal error : encodeCustomAttrElemType: unrecognized custom element type

1 participant