Files
carbon-lang/explorer/testdata/mixin/self_substitution.carbon
T
Richard Smith 212188a922 Prefer to put STDOUT CHECK at the end of the file. (#3073)
Allow interleaving of STDOUT and STDERR check lines. Put STDOUT lines
after the line they're attached to, and STDERR lines before. If no
STDOUT check line is attached to any line, then put them all at the end
of the file instead.

This is intended to better handle the case where stdout contains
unreplaced mentions of line numbers, and also reflects that stdout is
typically a consequence of the test rather than commentary on it, so
placing it after the test seems likely to read better.
2023-08-08 19:51:52 +00:00

37 lines
841 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
package ExplorerTest api;
__mixin Operations {
// Here Self which is both the input and output type is a type variable
fn F[self: Self](x: Self) -> Self {
return x;
}
}
class Point {
fn Origin() -> Point {
return {.x = 0, .y = 0};
}
var x: i32;
var y: i32;
__mix Operations;
}
fn Main() -> i32 {
var p1: Point = Point.Origin();
var p2: Point = {.x = 42, .y = 1};
// After accessing the mixin member F through a Point object, the
// input and output type variables of F get substituted with
// the Point class type
var p3: Point = p1.F(p2);
return p3.x - 42;
}
// CHECK:STDOUT: result: 0