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-12315] Extension of nested type does not have access to types it is nested in #54745

Closed
ktoso opened this issue Mar 4, 2020 · 1 comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis

Comments

@ktoso
Copy link
Member

ktoso commented Mar 4, 2020

Previous ID SR-12315
Radar rdar://problem/60230568
Original Reporter @ktoso
Type Bug
Status Resolved
Resolution Duplicate
Environment

Apple Swift version 5.2 (swiftlang-1103.0.22 clang-1103.0.22)
Apple Swift version 5.1.3 (swiftlang-1100.0.282.1 clang-1100.0.33.15)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, TypeChecker
Assignee None
Priority Medium

md5: 9705f88c3c600bbce103a2deadb3c46c

duplicates:

  • SR-4706 Name lookup in nested scopes is too restrictive

Issue Description:

Wording in title perhaps a bit confusing, so here's an example which I'd expect to work:

This works fine, I'm in Top.Middle.Hi and can use Middle however I want:

struct Top {
    struct Middle {
        struct Hi {
            func ret() -> Middle? { return nil }
        }
    }
}

Since the triple nesting gets pretty annoying, I refactor my code into an extension, like so:

extension Top.Middle.Hi {
    func nope() -> Middle? { return nil }
}
error: repl.swift:10:20: error: use of undeclared type 'Middle'
    func nope() -> Middle? { return nil }
                   ^~~~~~

which does not work, as suddenly I can't use Middle.

My current workaround is to define typealiases in the extension so the refactored code can use the short names... I would love to not have to do this. Visibility rules should not really change depending on if I declare the functions in the actual struct or in an extension IMO.

For context: we use nesting a lot for the sake of namespacing, so Top is more like "Namespace" so basically all code of larger modules already starts at one indentation level, then various types need to be in Middle and then have actual implementation specific types inside... This means this nesting pattern is quite common (or we end up polluting library user namespace with "popular names" which we'd like to avoid)

@beccadax
Copy link
Contributor

beccadax commented Mar 9, 2020

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself type checker Area → compiler: Semantic analysis
Projects
None yet
Development

No branches or pull requests

2 participants