mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-05 22:02:55 +01:00
Implement rename me -> self (#2444)
Implements change proposed in #1382 Replaces #1624
This commit is contained in:
+10
-10
@@ -10,8 +10,8 @@
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector {
|
||||
fn Add[me: Self](b: Self) -> Self;
|
||||
fn Scale[me: Self](v: i32) -> Self;
|
||||
fn Add[self: Self](b: Self) -> Self;
|
||||
fn Scale[self: Self](v: i32) -> Self;
|
||||
}
|
||||
|
||||
class Point {
|
||||
@@ -20,20 +20,20 @@ class Point {
|
||||
}
|
||||
|
||||
external impl Point as Vector {
|
||||
fn Add[me: Point](b: Point) -> Point {
|
||||
return {.x = me.x + b.x, .y = me.y + b.y};
|
||||
fn Add[self: Point](b: Point) -> Point {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
fn Scale[me: Point](v: i32) -> Point {
|
||||
return {.x = me.x * v, .y = me.y * v};
|
||||
fn Scale[self: Point](v: i32) -> Point {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
}
|
||||
|
||||
external impl Point as Vector {
|
||||
fn Add[me: Point](b: Point) -> Point {
|
||||
return {.x = me.x + b.x, .y = me.y + b.y};
|
||||
fn Add[self: Point](b: Point) -> Point {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
fn Scale[me: Point](v: i32) -> Point {
|
||||
return {.x = me.x * v, .y = me.y * v};
|
||||
fn Scale[self: Point](v: i32) -> Point {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/impl/fail_ambiguous_impl.carbon:[[@LINE+1]]: ambiguous implementations of interface Vector for class Point
|
||||
}
|
||||
|
||||
+10
-10
@@ -9,8 +9,8 @@
|
||||
package ExplorerTest api;
|
||||
|
||||
interface Vector(T:! Type) {
|
||||
fn Add[me: Self](b: Self) -> Self;
|
||||
fn Scale[me: Self](v: T) -> Self;
|
||||
fn Add[self: Self](b: Self) -> Self;
|
||||
fn Scale[self: Self](v: T) -> Self;
|
||||
}
|
||||
|
||||
class Point(T:! Type) {
|
||||
@@ -19,20 +19,20 @@ class Point(T:! Type) {
|
||||
}
|
||||
|
||||
external impl Point(i32) as Vector(i32) {
|
||||
fn Add[me: Self](b: Self) -> Self {
|
||||
return {.x = me.x + b.x, .y = me.y + b.y};
|
||||
fn Add[self: Self](b: Self) -> Self {
|
||||
return {.x = self.x + b.x, .y = self.y + b.y};
|
||||
}
|
||||
fn Scale[me: Self](v: i32) -> Self {
|
||||
return {.x = me.x * v, .y = me.y * v};
|
||||
fn Scale[self: Self](v: i32) -> Self {
|
||||
return {.x = self.x * v, .y = self.y * v};
|
||||
}
|
||||
}
|
||||
|
||||
external impl forall [T:! Type] Point(T) as Vector(T) {
|
||||
fn Add[me: Self](b: Self) -> Self {
|
||||
return me;
|
||||
fn Add[self: Self](b: Self) -> Self {
|
||||
return self;
|
||||
}
|
||||
fn Scale[me: Self](v: T) -> Self {
|
||||
return me;
|
||||
fn Scale[self: Self](v: T) -> Self {
|
||||
return self;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -12,16 +12,16 @@ package ExplorerTest api;
|
||||
class Cell(T:! Type) {
|
||||
fn Create(x: T) -> Cell(T) { return { .data = x }; }
|
||||
|
||||
fn Get[me: Self]() -> T {
|
||||
return me.data;
|
||||
fn Get[self: Self]() -> T {
|
||||
return self.data;
|
||||
}
|
||||
fn Put[addr me: Self*](x: T) {
|
||||
(*me).data = x;
|
||||
fn Put[addr self: Self*](x: T) {
|
||||
(*self).data = x;
|
||||
}
|
||||
fn Update[addr me: Self*, U:! ImplicitAs(T)](x: U) {
|
||||
(*me).data = x;
|
||||
fn Update[addr self: Self*, U:! ImplicitAs(T)](x: U) {
|
||||
(*self).data = x;
|
||||
}
|
||||
fn CreateOther[me: Self, U:! Type](x: U) -> Cell(U) {
|
||||
fn CreateOther[self: Self, U:! Type](x: U) -> Cell(U) {
|
||||
return {.data = x};
|
||||
}
|
||||
var data: T;
|
||||
|
||||
+2
-2
@@ -10,12 +10,12 @@
|
||||
package ExplorerTest api;
|
||||
|
||||
interface I(T:! Type) {
|
||||
fn F[me: Self](t: T, o: Self) -> Self;
|
||||
fn F[self: Self](t: T, o: Self) -> Self;
|
||||
}
|
||||
|
||||
class X(U:! Type) {
|
||||
impl as I(U) {
|
||||
fn F[me: Self](u: U, o: Self) -> Self { return {.m = u, .n = me.n + o.n}; }
|
||||
fn F[self: Self](u: U, o: Self) -> Self { return {.m = u, .n = self.n + o.n}; }
|
||||
}
|
||||
var m: U;
|
||||
var n: i32;
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ package ExplorerTest api;
|
||||
|
||||
interface Number {
|
||||
fn Zero() -> Self;
|
||||
fn Add[me: Self](other: Self) -> Self;
|
||||
fn Add[self: Self](other: Self) -> Self;
|
||||
}
|
||||
|
||||
class Point(T:! Number) {
|
||||
@@ -21,13 +21,13 @@ class Point(T:! Number) {
|
||||
|
||||
external impl i32 as Number {
|
||||
fn Zero() -> i32 { return 0; }
|
||||
fn Add[me: i32](other: i32) -> i32 { return me + other; }
|
||||
fn Add[self: i32](other: i32) -> i32 { return self + other; }
|
||||
}
|
||||
|
||||
external impl forall [U:! Number] Point(U) as Number {
|
||||
fn Zero() -> Point(U) { return {.x = U.Zero(), .y = U.Zero() }; }
|
||||
fn Add[me: Point(U)](other: Point(U)) -> Point(U) {
|
||||
return {.x = me.x.Add(other.x), .y = me.y.Add(other.y)};
|
||||
fn Add[self: Point(U)](other: Point(U)) -> Point(U) {
|
||||
return {.x = self.x.Add(other.x), .y = self.y.Add(other.y)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ package ExplorerTest api;
|
||||
|
||||
interface Number {
|
||||
fn Zero() -> Self;
|
||||
fn Add[me: Self](other: Self) -> Self;
|
||||
fn Add[self: Self](other: Self) -> Self;
|
||||
}
|
||||
|
||||
class Point(T:! Number) {
|
||||
@@ -21,13 +21,13 @@ class Point(T:! Number) {
|
||||
|
||||
external impl i32 as Number {
|
||||
fn Zero() -> i32 { return 0; }
|
||||
fn Add[me: i32](other: i32) -> i32 { return me + other; }
|
||||
fn Add[self: i32](other: i32) -> i32 { return self + other; }
|
||||
}
|
||||
|
||||
external impl forall [U:! Number] Point(U) as Number {
|
||||
fn Zero() -> Point(U) { return {.x = U.Zero(), .y = U.Zero() }; }
|
||||
fn Add[me: Point(U)](other: Point(U)) -> Point(U) {
|
||||
return {.x = me.x.Add(other.x), .y = me.y.Add(other.y)};
|
||||
fn Add[self: Point(U)](other: Point(U)) -> Point(U) {
|
||||
return {.x = self.x.Add(other.x), .y = self.y.Add(other.y)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -11,7 +11,7 @@ package ExplorerTest api;
|
||||
|
||||
interface Number {
|
||||
fn Zero() -> Self;
|
||||
fn Add[me: Self](other: Self) -> Self;
|
||||
fn Add[self: Self](other: Self) -> Self;
|
||||
}
|
||||
|
||||
class Point(T:! Number) {
|
||||
@@ -21,14 +21,14 @@ class Point(T:! Number) {
|
||||
|
||||
external impl i32 as Number {
|
||||
fn Zero() -> i32 { return 0; }
|
||||
fn Add[me: i32](other: i32) -> i32 { return me + other; }
|
||||
fn Add[self: i32](other: i32) -> i32 { return self + other; }
|
||||
}
|
||||
|
||||
external impl forall [U:! Number] Point(U) as Number {
|
||||
// Allowed: `Self` means `Point(U)` here.
|
||||
fn Zero() -> Self { return {.x = U.Zero(), .y = U.Zero() }; }
|
||||
fn Add[me: Self](other: Self) -> Self {
|
||||
return {.x = me.x.Add(other.x), .y = me.y.Add(other.y)};
|
||||
fn Add[self: Self](other: Self) -> Self {
|
||||
return {.x = self.x.Add(other.x), .y = self.y.Add(other.y)};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user