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

Private trait methods should be available to types that implement them #605

Closed
yorickpeterse opened this issue Sep 11, 2023 · 2 comments
Closed
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers bug Defects, unintended behaviour, etc compiler Changes related to the compiler
Milestone

Comments

@yorickpeterse
Copy link
Collaborator

When a class implements a trait that provides private methods, these methods should be available to the class, regardless of what module/namespace the trait is defined in. This removes the need for making such methods public in order to use them, which in turn prevents leaking of implementation details.

@yorickpeterse yorickpeterse added accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers compiler Changes related to the compiler labels Sep 11, 2023
@yorickpeterse yorickpeterse added this to the 0.14.0 milestone Oct 14, 2023
@bartlomieju
Copy link
Contributor

I'm having trouble reproducing it:

mkdir -p /tmp/test
cd /tmp/test
mkdir -p src/greet
mkdir -p src/person
echo 'trait pub Greet {
  fn greet -> String
}' > src/greet/a.inko
echo 'import greet.a.Greet

class Person {
  let @greeting: String
}

impl Greet for Person {
  fn greet -> String {
    @greeting
  }
}' > src/person/b.inko
inko check

There's no error raised here. I'm probably missing some context here...

@yorickpeterse
Copy link
Collaborator Author

@bartlomieju I don't remember what the original way to reproduce this was. I wouldn't be surprised if making private symbols namespace private (instead of module private) fixed part of this.

However, the following still fails:

# src/foo.inko
trait pub Foo {
  fn foo {
    42
  }
}

# src/bar.inko
import foo.Foo

class Bar {
  fn baz {}
}

impl Foo for Bar {}

fn example(value: Bar) {
  value.foo
}

This fails with:

src/bar.inko:10:3 error(invalid-call): the method 'foo' exists but is private

If the method foo is defined directly on Bar (as private) it works fine. The problem here is that trait methods added to a class use the same ModuleId as the module they're defined in. The fix is probably to just get the ModuleId of the class the method is defined on, and then use that, though I'm not entirely sure that's all that's needed.

@yorickpeterse yorickpeterse added the bug Defects, unintended behaviour, etc label Nov 16, 2023
bartlomieju added a commit to bartlomieju/inko that referenced this issue Nov 25, 2023
This commit fixes type checking of class that implement a trait which
contains a private method with a default implementation. Previously
usage of such method resulted in an error during type checking saying
that the method is private.

Changelog: fixed

Closes inko-lang#605
bartlomieju added a commit to bartlomieju/inko that referenced this issue Nov 25, 2023
This commit fixes type checking of class that implement a trait which
contains a private method with a default implementation. Previously
usage of such method resulted in an error during type checking saying
that the method is private.

Changelog: fixed

Closes inko-lang#605
bartlomieju added a commit to bartlomieju/inko that referenced this issue Nov 25, 2023
This commit fixes type checking of class that implement a trait which
contains a private method with a default implementation. Previously
usage of such method resulted in an error during type checking saying
that the method is private.

Changelog: fixed

Closes inko-lang#605
bartlomieju added a commit to bartlomieju/inko that referenced this issue Nov 27, 2023
This commit fixes type checking of class that implement a trait which
contains a private method with a default implementation. Previously the
usage of such method resulted in an error during type checking saying
that the method is private.

Changelog: fixed

Closes inko-lang#605
yorickpeterse pushed a commit that referenced this issue Nov 27, 2023
This commit fixes type checking of class that implement a trait which
contains a private method with a default implementation. Previously the
usage of such method resulted in an error during type checking saying
that the method is private.

This fixes #605.

Changelog: fixed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepting contributions Issues that are suitable to be worked on by anybody, not just maintainers bug Defects, unintended behaviour, etc compiler Changes related to the compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants