carbon-lang
carbon-lang copied to clipboard
Support aliasing an interface method as a class member
Description of the bug:
This is the feature version of #2583 (now that the crash is fixed), to support aliasing an interface method as a class member.
What did you do, or what's a simple way to reproduce the bug?
package sample api;
interface Printable {
fn PrintIt[self: Self]();
}
impl String as Printable {
fn PrintIt[self: String]() {
Print(self);
}
}
class Vector(T:! type) {
var x: T;
alias PrintIt = Printable.PrintIt;
}
// Conditionally implement the API for certain `T`s.
impl forall [U:! Printable] Vector(U) as Printable {
fn PrintIt[self: Self]() {
Print("{{");
self.x.PrintIt();
Print("}");
}
}
fn Main() -> i32 {
var v: Vector(String) = {.x = "test"};
v.(Printable.PrintIt)();
v.PrintIt();
return 42;
}
What did you expect to happen?
That the alias makes using the member name equivalent to using a qualified member name in a call. Basically, lines 30 and 31 should be equivalent:
v.(Printable.PrintIt)();
v.PrintIt();
What actually happened?
Currently unsupported.
Any other information, logs, or outputs that you want to share?
No response
I think this is a small fix, the former will cause runtime format error.
Print("{");
->
Print("{{");
@redbopo Thanks, fixed the example. That's the result of a separate bugfix I recently put in. :)
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please comment or remove the inactive label. The long term label can also be added for issues which are expected to take time. \n\n\n This issue is labeled inactive because the last activity was over 90 days ago.
Closing explorer-specific issues as not-planned for now due to our decision to prioritize working on the toolchain over other implementation work in the near term: https://github.com/carbon-language/carbon-lang/blob/trunk/proposals/p3532.md