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

Should an adapter have access to protected fields of its adapted type? #4560

Open
zygoloid opened this issue Nov 20, 2024 · 0 comments
Open
Labels
design idea An issue recording a specific language design idea that folks can potentially pick up. long term Issues expected to take over 90 days to resolve.

Comments

@zygoloid
Copy link
Contributor

Should this be valid:

class A {
  protected var a: i32;
}
class B {
  extend adapt A;
  fn F[self: Self]() -> i32 { return self.a; }
}

On the one hand, adapting a class is somewhat like inheritance, so perhaps an adapter should be able to access protected fields. On the other hand, adapting a class is not inheritance in various ways. Note that A is a final class; if it inherited a from one of its base classes, it may not expect that any code outside A and its base class can access that field. (Maybe we might even want to reject protected members in final classes.)

If we don't allow this, one could still use friend declarations to allow specific adapters to access non-public class members. The design currently doesn't permit adapters to access protected members of the adapted type; this came up because the toolchain currently does (though we plan to change it to match the current design).

@zygoloid zygoloid added long term Issues expected to take over 90 days to resolve. design idea An issue recording a specific language design idea that folks can potentially pick up. labels Nov 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design idea An issue recording a specific language design idea that folks can potentially pick up. long term Issues expected to take over 90 days to resolve.
Projects
None yet
Development

No branches or pull requests

1 participant