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

[SR-4706] Name lookup in nested scopes is too restrictive #47283

Open
dabrahams opened this issue Apr 26, 2017 · 7 comments
Open

[SR-4706] Name lookup in nested scopes is too restrictive #47283

dabrahams opened this issue Apr 26, 2017 · 7 comments
Labels
compiler The Swift compiler in itself improvement

Comments

@dabrahams
Copy link
Collaborator

Previous ID SR-4706
Radar rdar://problem/31838975
Original Reporter @dabrahams
Type Improvement
Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Improvement
Assignee None
Priority Medium

md5: 145ae74568a9818327c3395ef2066493

is duplicated by:

  • SR-9056 Nested type not in scope in own extension
  • SR-12315 Extension of nested type does not have access to types it is nested in

relates to:

  • SR-3834 Extensions of nested types are in wrong namespace

Issue Description:

This is annoying, and makes nesting less useful than it should be:

enum X {
  struct Y {}
  struct Z {}
}
extension X.Z {
  typealias A = Y // error: use of undeclared type 'Y'
}

we ought to make Y visible without qualification in X.

Not sure if this is formally a defect, but I consider it to be at least a usability bug.

@dabrahams
Copy link
Collaborator Author

@swift-ci create

@slavapestov
Copy link
Member

Should all members of X be visible inside the extension as well, or only Y?

@dabrahams
Copy link
Collaborator Author

All non-instance members should be visible. What could make Y special?

Here's another example, just to show how regressive it is:

extension Unicode.DefaultScalarView.Index : Comparable {
  static func < (lhs: Index, rhs: Index) -> Bool { return lhs < rhs } // error: use of undeclared type 'Index'
  static func == (lhs: Index, rhs: Index) -> Bool { return lhs == rhs }
}

The smallest version I could get it to eat was:

extension Unicode.DefaultScalarView.Index : Comparable {
  static func < (
    lhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
    rhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
  ) -> Bool { return lhs < rhs }
  
  static func == (
    lhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index,
    rhs: Unicode.DefaultScalarView<CodeUnits,Encoding>.Index
  ) -> Bool { return lhs == rhs }
}

@slavapestov
Copy link
Member

If you use master, then you should be able to write Unicode.DefaultScalarView.Index

@slavapestov
Copy link
Member

I agree it's verbose though. I'll see if we can change the name lookup rules.

@dabrahams
Copy link
Collaborator Author

If you use master, then you should be able to write Unicode.DefaultScalarView.Index

That must be a recent change, because I'm very close to master

@slavapestov
Copy link
Member

Yes, it's pretty recent.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler The Swift compiler in itself improvement
Projects
None yet
Development

No branches or pull requests

2 participants