Files
carbon-lang/explorer/testdata/alias/interface_method_as_class_member.carbon
T
Lucile Rose Nihlen c180e6367b [explorer] fix assert when aliasing interface as member (#2792)
Note that this code still results in a compilation error pending the merge of #2628, this just prevents the assertion from happening.

Closes #2583.
2023-04-24 08:05:31 -07:00

42 lines
975 B
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// AUTOUPDATE
// RUN: %{not} %{explorer-run}
// RUN: %{not} %{explorer-run-trace}
package ExplorerTest 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"};
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/alias/interface_method_as_class_member.carbon:[[@LINE+1]]: Member access to aliases is not yet supported.
v.PrintIt();
return 42;
}