Skip to content

Fix #7931: Resolve opened namespaces for attributes in recursive scopes#19502

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784
Draft

Fix #7931: Resolve opened namespaces for attributes in recursive scopes#19502
Copilot wants to merge 2 commits intomainfrom
copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 26, 2026

Description

Fixes nested module attributes not being resolved in namespace rec / module rec scopes. Previously, using [<Extension>] on a module inside namespace rec would fail with FS0039: The type 'Extension' is not defined, even when open System.Runtime.CompilerServices was in scope.

Root Cause

In recursive scopes, open declarations are processed in Phase1AB — after Phase1A builds module/type entities. But module attributes are checked during Phase1A using envInitial, which doesn't yet include the opened namespaces. In non-recursive scopes, opens are processed sequentially before module attributes are checked, so this issue doesn't occur.

Changes Made

  • src/Compiler/Checking/CheckDeclarations.fs: Added preProcessOpensForPhase1A helper that silently resolves open declarations before Phase1A attribute checking. Uses suppressErrorReporting and TemporarilySuspendReportingTypecheckResultsToSink to avoid duplicate diagnostics (since opens are re-processed properly in Phase1AB). Applied at two levels:
    1. Top-level opens in TcMutRecDefns_Phase1 (fixes namespace rec case)
    2. Inner opens in TcTyconDefnCore_Phase1A_BuildInitialModule (fixes nested module case)
  • Regression tests: Added 8 test cases in AttributeResolutionInRecursiveScopes.fs covering the issue scenarios (Extension attribute on modules/types in namespace rec, nested modules, multiple opens, module rec, and non-recursive baseline).
  • Release notes: Added entry to docs/release-notes/.FSharp.Compiler.Service/11.0.100.md.

Testing

  • All 8 new regression tests pass
  • All 158 existing custom attribute tests pass
  • 636/638 broader conformance tests pass (2 failures are pre-existing and unrelated)

📱 Kick off Copilot coding agent tasks wherever you are with GitHub Mobile, available on iOS and Android.

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again

@T-Gro
Copy link
Copy Markdown
Member

T-Gro commented Mar 27, 2026

@copilot : Try again.

@abonie
Copy link
Copy Markdown
Member

abonie commented Mar 31, 2026

@copilot Try again

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 31, 2026

@copilot Try again

Implemented the fix in commit d0e2dac (with release notes in c8d283c).

Root cause: In recursive scopes (namespace rec/module rec), open declarations were only processed in Phase1AB — after Phase1A builds module entities. But module attributes need opened namespaces during Phase1A.

Fix: Added preProcessOpensForPhase1A that silently resolves opens before Phase1A attribute checking, applied at both the top level and nested module level. All 158 custom attribute tests pass, plus 8 new regression tests for issue #7931.

Copilot AI changed the title [WIP] Copilot Request Fix #7931: Resolve opened namespaces for attributes in recursive scopes Mar 31, 2026
Copilot AI requested a review from abonie March 31, 2026 15:21
@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784 branch from c8d283c to 676aa49 Compare April 9, 2026 11:30
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 9, 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

@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784 branch 4 times, most recently from 7f17efd to baf9133 Compare April 9, 2026 15:25
Copilot AI and others added 2 commits April 10, 2026 12:18
Pre-process open declarations before Phase1A attribute checking in
recursive scopes (namespace rec / module rec). Previously, opens were
only processed in Phase1AB after module entities were built, but module
attributes needed access to opened namespaces during Phase1A.

The fix adds preProcessOpensForPhase1A which silently resolves opens
before Phase1A, making opened namespaces available for attribute
resolution on modules and types in recursive scopes.

Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/20a6e4bb-a5f1-45cc-b80d-ee1110cd8812

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/20a6e4bb-a5f1-45cc-b80d-ee1110cd8812

Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
@T-Gro T-Gro force-pushed the copilot/fix-9141961-29048891-9983b77b-6647-424c-befc-6bcc6711d784 branch from baf9133 to b90f44e Compare April 10, 2026 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: New

Development

Successfully merging this pull request may close these issues.

3 participants