Skip to content
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

[AST] Fix best import kind when value decl is a typealias of an existential type #72738

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

li3zhen1
Copy link
Contributor

@li3zhen1 li3zhen1 commented Mar 31, 2024

Resolves #72724 .

Fixed behaviors:

/Users/lizhen/Projects/swift-projects/build/Ninja-DebugAssert/swift-macosx-arm64/bin/swift-frontend ./moduleB.swift -I . -L . -l./moduleA -typecheck
./moduleB.swift:3:17: error: type alias 'TypeAlias' (aka 'any Protocol') cannot be imported as 'protocol'
1 │
2 │ // Module B
3 │ import protocol ModuleA.TypeAlias 
  │                 ╰─ error: type alias 'TypeAlias' (aka 'any Protocol') cannot be imported as 'protocol'
4 │ import typealias ModuleA.TypeAlias

/Users/lizhen/Projects/swift-debug/./ModuleA.swift:3:18: note: 'TypeAlias' declared here
1 │ // Module A
2 │ public protocol Protocol {}
3 │ public typealias TypeAlias = any Protocol
  │                  ╰─ note: 'TypeAlias' declared here
4 │

@li3zhen1 li3zhen1 force-pushed the fix-incorrect-existential-import branch 2 times, most recently from b45bda9 to aaa58a9 Compare April 1, 2024 01:15
@li3zhen1 li3zhen1 force-pushed the fix-incorrect-existential-import branch from aaa58a9 to e738059 Compare April 1, 2024 01:17
@DougGregor
Copy link
Member

@li3zhen1 could you add a test case that checks the new behavior? It could go into test/ImportResolution/import-specific-fixits.swift with other tests of this diagnostic.

@li3zhen1
Copy link
Contributor Author

li3zhen1 commented Apr 2, 2024

Added. Thanks.

@simanerush
Copy link
Member

@swift-ci please smoke test

Copy link
Collaborator

@AnthonyLatsis AnthonyLatsis left a comment

Choose a reason for hiding this comment

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

This fix is fine, but that we are looking through existentials in getAnyGeneric is a bit disturbing and rather counterintuitive these days. Could we see whether fixing that instead breaks anything?

swift/lib/AST/Type.cpp

Lines 84 to 86 in e431216

GenericTypeDecl *CanType::getAnyGeneric() const {
if (auto existential = dyn_cast<ExistentialType>(*this))
return existential->getConstraintType()->getAnyGeneric();

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.

import typealias causes invalid error claiming the symbol is a protocol
4 participants