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-10113] Nested types can be redeclared in the same class hierarchy #52515

Open
hamishknight opened this issue Mar 15, 2019 · 2 comments
Open
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

@hamishknight
Copy link
Collaborator

Previous ID SR-10113
Radar None
Original Reporter @hamishknight
Type Bug
Environment

Swift version 5.0-dev (LLVM 94d957ca75, Swift 1d2e2803af)
Target: x86_64-apple-darwin18.2.0

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

md5: 60d05253f55e0543cd9234c96d3fe727

Issue Description:

The following is currently legal:

class C {
  struct X {}
}
class D : C {
  struct X {}
}

However, arguably the second nested definition of X should be rejected with a redeclaration error.

@swift-ci
Copy link
Collaborator

Comment by Sidharth Juyal (JIRA)

This issue is described here: https://stackoverflow.com/q/55186648/286094

IMO this is not a programmer bug, I would expect it should just work as desired as in case of other languages like C++

struct CommonField {
    std::string name;
    CommonField(const std::string &name) : name(name) {}
};

struct Base {
    struct Field : public CommonField {
        Field(const std::string &name) : CommonField(name) {}
    };
};

struct Derived: public Base {
    struct Field : public CommonField {
        Field(const std::string &name) : CommonField(name) {}
    };
};

void run()
{
    auto a = CommonField("field");
    auto b = Base::Field("base.field");
    auto c = Derived::Field("derived.field");
}

@belkadan
Copy link
Contributor

Yeah, I think this is shadowing, not redeclaration. We don't treat it as shadowing today, though.

@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
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

3 participants