Files
carbon-lang/explorer/testdata/named_constraint/impl_constraint.carbon
T
Richard Smith 9e8cacae00 Implement support for named constraints (#2359)
Basic support for named constraints as described in [the generics design](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/generics/details.md#named-constraints). Support is provided for `extends` and `impl` declarations in `constraint`, but not yet for member aliases.

The missing prelude named constraints `Add`, `Mul`, `Ordered`, etc. are also added.
2022-11-04 16:23:02 -07:00

38 lines
728 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: %{explorer-run}
// RUN: %{explorer-run-trace}
// CHECK:STDOUT: result: 12
package ExplorerTest api;
interface Runnable {
fn Run[me: Self]() -> i32;
}
interface Walkable {
fn Walk[me: Self]() -> i32;
}
constraint Traversible {
extends Runnable;
extends Walkable;
}
external impl i32 as Traversible {
fn Run[me: i32]() -> i32 {
return 10 * me;
}
fn Walk[me: i32]() -> i32 {
return me + 1;
}
}
fn Main() -> i32 {
var n: i32 = 1;
return n.(Runnable.Run)() + n.(Walkable.Walk)();
}