-
Notifications
You must be signed in to change notification settings - Fork 859
Fix #7931: Resolve opened namespaces for attributes in recursive scopes #19502
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Copilot
wants to merge
5
commits into
main
Choose a base branch
from
copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
53b6ae8
Fix #7931: Resolve opened namespaces for attributes in recursive scopes
Copilot c8bd4f1
Add release notes for #7931 fix
Copilot 4138cf3
Restrict open preprocessing to ModuleOrNamespace targets and add nega…
T-Gro 2b14389
Add edge-case tests for invalid open and forward-reference in namespa…
T-Gro ce04c19
Merge branch 'main' into copilot/fix-9141961-29048891-9983b77b-6647-4…
T-Gro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
193 changes: 193 additions & 0 deletions
193
...icGrammarElements/CustomAttributes/AttributeUsage/AttributeResolutionInRecursiveScopes.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,193 @@ | ||
| // Copyright (c) Microsoft Corporation. All Rights Reserved. See License.txt in the project root for license information. | ||
|
|
||
| namespace Conformance.BasicGrammarElements | ||
|
|
||
| open Xunit | ||
| open FSharp.Test.Compiler | ||
|
|
||
| module AttributeResolutionInRecursiveScopes = | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/7931 | ||
| [<Fact>] | ||
| let ``Extension attribute on module in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| module Module = | ||
| [<Extension>] | ||
| let ext1 (x: int) = x.ToString() | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/7931 | ||
| [<Fact>] | ||
| let ``Extension attribute on type in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| type T() = | ||
| class end | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5795 - Custom attribute used on type and let in rec module | ||
| [<Fact>] | ||
| let ``Custom attribute used on type and let in rec module`` () = | ||
| FSharp """ | ||
| module rec M | ||
|
|
||
| type CustomAttribute() = | ||
| inherit System.Attribute() | ||
|
|
||
| [<Custom>] type A = | A | ||
| [<Custom>] let a = () | ||
| """ | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Nested module case: open inside outer module, attribute on inner module | ||
| [<Fact>] | ||
| let ``Open inside nested module resolves for attribute on inner module in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| module Outer = | ||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| module Inner = | ||
| [<Extension>] | ||
| let ext1 (x: int) = x.ToString() | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Non-recursive baseline: should always work | ||
| [<Fact>] | ||
| let ``Extension attribute works without rec - baseline`` () = | ||
| FSharp """ | ||
| namespace Ns | ||
|
|
||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| module Module = | ||
| [<Extension>] | ||
| let ext1 (x: int) = x.ToString() | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Multiple opens in namespace rec | ||
| [<Fact>] | ||
| let ``Multiple opens resolve for attributes in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open System | ||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| module Module = | ||
| [<Extension>] | ||
| [<Obsolete("test")>] | ||
| let ext1 (x: int) = x.ToString() | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Open in module rec resolves for module attributes | ||
| [<Fact>] | ||
| let ``Open in module rec resolves for nested module attribute`` () = | ||
| FSharp """ | ||
| module rec M | ||
|
|
||
| open System.Runtime.CompilerServices | ||
|
|
||
| [<Extension>] | ||
| module Inner = | ||
| [<Extension>] | ||
| let ext1 (x: int) = x.ToString() | ||
| """ | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Open with Obsolete attribute in namespace rec | ||
| [<Fact>] | ||
| let ``Obsolete attribute resolves via open in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open System | ||
|
|
||
| [<Obsolete("deprecated")>] | ||
| module DeprecatedModule = | ||
| let x = 42 | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldSucceed | ||
|
|
||
| // Negative test: undefined attribute still errors in namespace rec | ||
| [<Fact>] | ||
| let ``Undefined attribute still errors in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| [<DoesNotExist>] | ||
| module M = | ||
| let x = 1 | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withErrorCode 39 | ||
|
|
||
| // Negative test: invalid open target still errors despite error suppression in pre-pass | ||
| [<Fact>] | ||
| let ``Invalid open target still errors in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open DoesNotExist.Namespace | ||
|
|
||
| [<System.Obsolete>] | ||
| module M = | ||
| let x = 1 | ||
| """ | ||
| |> asLibrary | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withErrorCode 39 | ||
|
|
||
| // Forward-reference open to sibling module in the same recursive scope | ||
| [<Fact>] | ||
| let ``Forward reference open to sibling module in namespace rec`` () = | ||
| FSharp """ | ||
| namespace rec Ns | ||
|
|
||
| open Ns.Later | ||
|
|
||
| module Earlier = | ||
| let x = Later.y | ||
|
|
||
| module Later = | ||
| let y = 42 | ||
| """ | ||
| |> asLibrary | ||
| |> withOptions [ "--nowarn:22"; "--nowarn:40" ] | ||
| |> typecheck | ||
| |> shouldSucceed | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test case is not reproing #5795, and in fact I think #5795 is not fixed by this PR - at the very minimum the comment should be removed