Skip to content

Fix AttributeUsage.AllowMultiple not inherited for C#-defined attributes#19315

Merged
T-Gro merged 2 commits intodotnet:mainfrom
edgarfgp:fix-17107-allowmultiple-inherited-csharp
Apr 14, 2026
Merged

Fix AttributeUsage.AllowMultiple not inherited for C#-defined attributes#19315
T-Gro merged 2 commits intodotnet:mainfrom
edgarfgp:fix-17107-allowmultiple-inherited-csharp

Conversation

@edgarfgp
Copy link
Copy Markdown
Contributor

@edgarfgp edgarfgp commented Feb 17, 2026

Description

The F# compiler was not walking the inheritance chain for IL-imported (C#) attribute types when checking AllowMultiple. The supersOfTyconRef function only used tcaug_super, which is not populated for IL types.

This fix parameterizes TryFindAttributeUsageAttribute with a getSuper resolver function. The caller in PostInferenceChecks now passes a resolver using GetSuperTypeOfType, which correctly handles both F# and IL-imported types via ILTypeDef.Extends.

Fixes #17107

Checklist

  • Test cases added
  • Release notes entry updated

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Feb 17, 2026

❗ Release notes required


✅ 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

@edgarfgp edgarfgp marked this pull request as ready for review February 17, 2026 19:01
@edgarfgp edgarfgp requested a review from a team as a code owner February 17, 2026 19:01
@edgarfgp
Copy link
Copy Markdown
Contributor Author

This is ready!

@edgarfgp edgarfgp closed this Feb 19, 2026
@edgarfgp edgarfgp reopened this Feb 19, 2026
Comment thread src/Compiler/TypedTree/TypedTreeOps.fs Outdated
Comment thread src/Compiler/Checking/PostInferenceChecks.fs Outdated
@edgarfgp edgarfgp force-pushed the fix-17107-allowmultiple-inherited-csharp branch from cd42e58 to c08bf2d Compare March 13, 2026 22:06
Copy link
Copy Markdown
Member

@T-Gro T-Gro left a comment

Choose a reason for hiding this comment

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

This is good now, thanks for the fix!

@edgarfgp edgarfgp force-pushed the fix-17107-allowmultiple-inherited-csharp branch from a4bb978 to 7834a63 Compare April 1, 2026 15:05
@edgarfgp
Copy link
Copy Markdown
Contributor Author

edgarfgp commented Apr 1, 2026

/azp run

@azure-pipelines
Copy link
Copy Markdown

Commenter does not have sufficient privileges for PR 19315 in repo dotnet/fsharp

@edgarfgp edgarfgp closed this Apr 1, 2026
@edgarfgp edgarfgp reopened this Apr 1, 2026
@edgarfgp
Copy link
Copy Markdown
Contributor Author

edgarfgp commented Apr 9, 2026

@T-Gro this is ready!!

@edgarfgp edgarfgp closed this Apr 10, 2026
@edgarfgp edgarfgp reopened this Apr 10, 2026
@edgarfgp
Copy link
Copy Markdown
Contributor Author

@T-Gro Closing this PR. I do not have much time to keep fixing merge conflicts . Feel free to pick the changes if needed. Thanks

@edgarfgp edgarfgp closed this Apr 13, 2026
@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Apr 14, 2026

@edgarfgp , ok, let me try resolving them 👍

T-Gro added a commit that referenced this pull request Apr 14, 2026
…tes (#17107)

The F# compiler was not walking the inheritance chain for IL-imported (C#)
attribute types when checking AllowMultiple. The supersOfTyconRef function
only used tcaug_super, which is not populated for IL types.

This fix simplifies TryFindAttributeUsageAttribute to only check the
current type, and adds a recursive allowsMultiple function in
PostInferenceChecks that walks the inheritance chain using
GetSuperTypeOfType, which correctly handles both F# and IL-imported types.

Based on work by edgarfgp in PR #19315.
Fixes #17107

Co-authored-by: edgarfgp <31915729+edgarfgp@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro reopened this Apr 14, 2026
@T-Gro T-Gro force-pushed the fix-17107-allowmultiple-inherited-csharp branch from 3dbe06f to 9d42343 Compare April 14, 2026 14:41
…tes (dotnet#17107)

The F# compiler was not walking the inheritance chain for IL-imported (C#)
attribute types when checking AllowMultiple. The supersOfTyconRef function
only used tcaug_super, which is not populated for IL types.

This fix simplifies TryFindAttributeUsageAttribute to only check the
current type, and adds a recursive allowsMultiple function in
PostInferenceChecks that walks the inheritance chain using
GetSuperTypeOfType, which correctly handles both F# and IL-imported types.

Based on work by edgarfgp in PR dotnet#19315.
Fixes dotnet#17107

Co-authored-by: edgarfgp <31915729+edgarfgp@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro force-pushed the fix-17107-allowmultiple-inherited-csharp branch from 9d42343 to 93849f3 Compare April 14, 2026 14:43
Switch TryFindAttributeUsageAttribute to use tryBindTyconRefAttributeCore
with ValueSome WellKnownILAttributes.AttributeUsageAttribute, enabling
O(1) early exit on IL types that lack [AttributeUsage]. This avoids a
full linear attribute scan at each level of the inheritance chain walk.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@T-Gro T-Gro merged commit 872352f into dotnet:main Apr 14, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

AttributeUsage.AllowMultiple is not inherited for attributes defined (subclassed) in C#

2 participants