carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Support aliasing an interface method as a class member

Open jonmeow opened this issue 2 years ago • 3 comments

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

jonmeow avatar Apr 24 '23 15:04 jonmeow

I think this is a small fix, the former will cause runtime format error.

Print("{");

->

Print("{{");

redbopo avatar May 02 '23 05:05 redbopo

@redbopo Thanks, fixed the example. That's the result of a separate bugfix I recently put in. :)

jonmeow avatar May 02 '23 15:05 jonmeow

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.

github-actions[bot] avatar Aug 01 '23 01:08 github-actions[bot]

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

chandlerc avatar Jan 20 '24 00:01 chandlerc