Skip to content

Fix conditional import parsing with access modifiers#2494

Merged
calda merged 1 commit intonicklockwood:developfrom
erichoracek:dev/eh/fix-conditional-import-parse
Apr 11, 2026
Merged

Fix conditional import parsing with access modifiers#2494
calda merged 1 commit intonicklockwood:developfrom
erichoracek:dev/eh/fix-conditional-import-parse

Conversation

@erichoracek
Copy link
Copy Markdown
Contributor

@erichoracek erichoracek commented Apr 11, 2026

Prevent sortImports from treating access-controlled declarations after an import as Swift 6 access-controlled imports. This keeps #if / #elseif import blocks intact when a branch-local declaration follows the import.

Could result in a change like this:

#if canImport(UIKit)
-import UIKit
-private struct Foo {}
-#elseif canImport(AppKit)
import AppKit
+import UIKit
private struct Foo {}
#endif

Prevent `sortImports` from treating access-controlled declarations after an import as Swift 6 access-controlled imports. This keeps `#if` / `#elseif` import blocks intact when a branch-local declaration follows the import.

Add a regression test covering conditional imports followed by `private` declarations.

Co-authored-by: Codex <noreply@openai.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.31%. Comparing base (e92eabf) to head (9f0efe1).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #2494      +/-   ##
===========================================
- Coverage    95.31%   95.31%   -0.01%     
===========================================
  Files          168      168              
  Lines        25381    25383       +2     
===========================================
+ Hits         24192    24193       +1     
- Misses        1189     1190       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Collaborator

@calda calda left a comment

Choose a reason for hiding this comment

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

Thanks Eric!

@calda calda merged commit 08e0f66 into nicklockwood:develop Apr 11, 2026
19 checks passed
@erichoracek
Copy link
Copy Markdown
Contributor Author

Thanks! This is blocking our adoption of the most recent release, should I also do a PR against main?

@calda
Copy link
Copy Markdown
Collaborator

calda commented Apr 11, 2026

I can cut a release of the develop branch

calda pushed a commit that referenced this pull request Apr 11, 2026
Co-authored-by: Codex <noreply@openai.com>
@calda
Copy link
Copy Markdown
Collaborator

calda commented Apr 11, 2026

@erichoracek
Copy link
Copy Markdown
Contributor Author

Thanks so much!

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.

2 participants