Files
carbon-lang/explorer/testdata/named_constraint/impl_constraint.carbon
T
2023-06-15 08:42:14 -07:00

36 lines
675 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
// CHECK:STDOUT: result: 12
package ExplorerTest api;
interface Runnable {
fn Run[self: Self]() -> i32;
}
interface Walkable {
fn Walk[self: Self]() -> i32;
}
constraint Traversible {
extend Runnable;
extend Walkable;
}
impl i32 as Traversible {
fn Run[self: i32]() -> i32 {
return 10 * self;
}
fn Walk[self: i32]() -> i32 {
return self + 1;
}
}
fn Main() -> i32 {
var n: i32 = 1;
return n.(Runnable.Run)() + n.(Walkable.Walk)();
}