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

Submodules cannot access private members of parents #4536

Closed
brson opened this issue Jan 19, 2013 · 6 comments
Closed

Submodules cannot access private members of parents #4536

brson opened this issue Jan 19, 2013 · 6 comments
Labels
A-resolve Area: Name resolution

Comments

@brson
Copy link
Contributor

brson commented Jan 19, 2013

mod foo {
    mod bar {
        // This doesn't resolve, nor does foo::S
        use super::S;

        fn make() -> S { fail }
    }

    priv struct S(());
}

fn main() { }
@bstrie
Copy link
Contributor

bstrie commented Apr 29, 2013

Still reproduces:

⌁ rustc 4536.rs
4536.rs:4:12: 4:21 error: failed to resolve import: super::S
4536.rs:4         use super::S;
                      ^~~~~~~~~
4536.rs:5:12: 5:19 error: failed to resolve import: foo::S
4536.rs:5         use foo::S;
                      ^~~~~~~
error: failed to resolve imports
error: aborting due to 3 previous errors

@graydon
Copy link
Contributor

graydon commented Apr 30, 2013

looks like "just" a bug, de-milestoning

@graydon
Copy link
Contributor

graydon commented Apr 30, 2013

hm. this is part of a pattern. re-milestoning and collecting into a metabug.

@emberian
Copy link
Member

Still reproduces:

[17:03:53]/tmp> rustc foo.rs
foo.rs:4:12: 4:20 error: unresolved import: found `S` in `foo` but it is private
foo.rs:4         use super::S;
                     ^~~~~~~~
foo.rs:4:12: 4:20 error: failed to resolve import `super::S`
foo.rs:4         use super::S;
                     ^~~~~~~~

Is this desired behavior? Should children be able to access its parent's privates? Should this extend to all ancestor modules?

If so, it should be easy to fix I think. For each resolve that "fails" due to privacy, check if the module is a child of wherever it resolved to, and if so, don't actually fail the resolve.

This happens in resolve_single_import, which is a huge function in resolve.rs. Should probably be handled in/around src/librustc/middle/resolve.rs:2434 (handily, I refactored this code to enable this enabling the "it's private" error).

It shouldn't affect performance much, I don't think, especially since it's so rare (the error path is hit very rarely afaict).

@pnkfelix
Copy link
Member

pnkfelix commented Jul 2, 2013

linking to #6143 for unified tracking of resolve

@catamorphism
Copy link
Contributor

Dup of #5238

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-resolve Area: Name resolution
Projects
None yet
Development

No branches or pull requests

6 participants