Skip to content

Conversation

@hi2gage
Copy link
Member

@hi2gage hi2gage commented Jan 8, 2026

Summary

  • Adds checkAttachedMacroAccess() to track import usage for macro attributes on package declarations
  • Fixes spurious "package import was not used in package declarations" warning when macros are used

Problem

When a macro attribute from an external module is applied to a package-level declaration, the compiler incorrectly emits:

warning: package import of 'X' was not used in package declarations

AccessControlChecker tracks import usage for types, global actors, and availability attributes, but not for macro attributes. The public case works because it has more comprehensive tracking, but package declarations have gaps.

Solution

Add checkAttachedMacroAccess() to AccessControlCheckerBase following the same pattern as checkGlobalActorAccess(). This iterates through attached macro attributes on package declarations and calls recordRequiredImportAccessLevelForDecl() to register the import usage.

Test Plan

Reproduction repo: https://github.com/hi2gage/swift-package-macro-import-warning-repro

Before fix:

warning: package import of 'Mocking' was not used in package declarations

After fix:
No warning (clean build)

Related Issue

Fixes #86375

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Package import warning incorrectly fires when using macro attributes on package declarations

1 participant