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

Swift macros should be able to use module names as namespaces #65485

Closed
kishikawakatsumi opened this issue Apr 27, 2023 · 2 comments · Fixed by #69457
Closed

Swift macros should be able to use module names as namespaces #65485

kishikawakatsumi opened this issue Apr 27, 2023 · 2 comments · Fixed by #69457

Comments

@kishikawakatsumi
Copy link

Description

The way Swift macros are syntactically defined and their appearance is quite similar to property wrappers and result builders, especially in the case of attached macros. Property wrappers and result builders can be qualified with module names as namespaces to avoid naming collisions.

On the other hand, macros have no way to avoid name collisions when the same macro name exists in different modules, resulting in an "ambiguous use" error. I believe that macros should also be able to use module names to represent their fully qualified names, just like property wrappers and result builders.

For example, property wrappers can be qualified by the module name as follows:

class ViewController: UIViewController {
  @Combine.Published var s = "..."
}

Result builders also can be qualified by the module name as follows.

@SwiftUI.ViewBuilder
func content() -> some View {
  Text("...")
}

Macros should be able to be qualified by the module name as well.

print(#Foundation.URL("https://swift.org/"))
@Swift.Observable
final class Dog {}
@ahoppen
Copy link
Contributor

ahoppen commented Apr 27, 2023

Tracked in Apple’s issue tracker as rdar://108621205

@ahoppen
Copy link
Contributor

ahoppen commented Apr 28, 2023

Since name lookup happens inside semantic analysis, which is done after parsing, I’m moving this to the swift repo.

@ahoppen ahoppen transferred this issue from apple/swift-syntax Apr 28, 2023
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 a pull request may close this issue.

2 participants