Implement rename me -> self (#2444)

Implements change proposed in #1382

Replaces #1624
This commit is contained in:
josh11b
2022-12-06 20:17:00 -08:00
committed by GitHub
parent d1210c4a50
commit 9c8fd6864e
287 changed files with 1727 additions and 1720 deletions
@@ -13,8 +13,8 @@ package ExplorerTest api;
interface Vector {
fn Zero() -> Self;
fn Add[addr me: Self*](b: Self);
fn Scale[addr me: Self*](v: i32);
fn Add[addr self: Self*](b: Self);
fn Scale[addr self: Self*](v: i32);
}
class Point {
@@ -24,13 +24,13 @@ class Point {
fn Zero() -> Self {
return {.x = 1, .y = 1};
}
fn Add[addr me: Self*](b: Self) {
(*me).x = (*me).x + b.x;
(*me).y = (*me).y + b.y;
fn Add[addr self: Self*](b: Self) {
(*self).x = (*self).x + b.x;
(*self).y = (*self).y + b.y;
}
fn Scale[addr me: Self*](v: i32) {
(*me).x = (*me).x * v;
(*me).y = (*me).y * v;
fn Scale[addr self: Self*](v: i32) {
(*self).x = (*self).x * v;
(*self).y = (*self).y * v;
}
}
}
+6 -6
View File
@@ -11,8 +11,8 @@ package ExplorerTest api;
interface Vector {
fn Zero() -> Self;
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 {
@@ -22,11 +22,11 @@ class Point {
fn Zero() -> Point {
return {.x = 0, .y = 0};
}
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};
}
}
}
+14 -14
View File
@@ -10,16 +10,16 @@
package ExplorerTest api;
interface AddMul {
fn Add[me: Self](o: Self) -> Self;
fn Mul[me: Self](o: Self) -> Self;
fn Add[self: Self](o: Self) -> Self;
fn Mul[self: Self](o: Self) -> Self;
}
external impl i32 as AddMul {
fn Add[me: i32](o: i32) -> i32 {
return me + o;
fn Add[self: i32](o: i32) -> i32 {
return self + o;
}
fn Mul[me: i32](o: i32) -> i32 {
return me * o;
fn Mul[self: i32](o: i32) -> i32 {
return self * o;
}
}
@@ -29,9 +29,9 @@ class Holder(T:! AddMul) {
interface Vector(Scalar:! AddMul) {
fn Zero() -> Self;
fn Add[me: Self](b: Self) -> Self;
fn Scale[me: Self](v: Scalar) -> Self;
fn Hold[me: Self](v: Scalar) -> Holder(Scalar);
fn Add[self: Self](b: Self) -> Self;
fn Scale[self: Self](v: Scalar) -> Self;
fn Hold[self: Self](v: Scalar) -> Holder(Scalar);
}
class Point {
@@ -41,13 +41,13 @@ class Point {
fn Zero() -> Point {
return {.x = 0, .y = 0};
}
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};
}
fn Hold[me: Point](v: i32) -> Holder(i32) {
fn Hold[self: Point](v: i32) -> Holder(i32) {
return {.v = v};
}
}
+4 -4
View File
@@ -11,12 +11,12 @@
package ExplorerTest api;
interface Apple(T:! Type) {
fn F[me: Self]() -> T;
fn F[self: Self]() -> T;
}
interface Banana {
extends Apple(i32);
fn G[me: Self]();
fn G[self: Self]();
}
class Carrot {
@@ -25,8 +25,8 @@ class Carrot {
// This impl also provides an `impl Carrot as Apple(i32)`.
external impl Carrot as Banana {
fn F[me: Self]() -> i32 { return me.n; }
fn G[me: Self]() { Print("Carrot.G"); }
fn F[self: Self]() -> i32 { return self.n; }
fn G[self: Self]() { Print("Carrot.G"); }
}
fn Main() -> i32 {
@@ -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,11 +20,11 @@ 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};
}
}
+6 -6
View File
@@ -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 {
@@ -21,11 +21,11 @@ class Point {
external impl Point as Vector {
// Allowed: `Self` means `Point` here.
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};
}
}
@@ -9,8 +9,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 {
@@ -21,11 +21,11 @@ class Point {
// Error: need to specify which type implementing `Vector` for.
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_external_impl_omit_self.carbon:[[@LINE+1]]: could not resolve 'Self'
external impl 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};
}
}
+6 -6
View File
@@ -9,8 +9,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,11 +20,11 @@ class Point {
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_external_impl_self.carbon:[[@LINE+1]]: could not resolve 'Self'
external impl Self 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};
}
}
+5 -5
View File
@@ -9,18 +9,18 @@
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 {
var x: i32;
var y: i32;
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) -> i32 {
fn Scale[self: Point](v: i32) -> i32 {
return 0;
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_impl_bad_member.carbon:[[@LINE+3]]: type error in member of implementation
// CHECK:STDERR: expected: fn (i32) -> class Point
@@ -9,16 +9,16 @@
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 {
var x: i32;
var y: i32;
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};
}
// CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/interface/fail_impl_missing_member.carbon:[[@LINE+1]]: implementation missing Scale
}
@@ -9,7 +9,7 @@
package ExplorerTest api;
interface Vector {
fn Add[me: Self](b: Self) -> Self;
fn Add[self: Self](b: Self) -> Self;
}
fn ScaleGeneric[T:! Vector](a: T, s: i32) -> T {
@@ -21,8 +21,8 @@ class Point {
var x: i32;
var y: i32;
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};
}
}
}
+2 -2
View File
@@ -9,8 +9,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 {
+6 -6
View File
@@ -10,19 +10,19 @@
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 {
var x: i32;
var y: i32;
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};
}
}
}
+10 -10
View File
@@ -10,19 +10,19 @@
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 Point1 {
var x: i32;
var y: i32;
impl Point1 as Vector {
fn Add[me: Point1](b: Point1) -> Point1 {
return {.x = me.x + b.x, .y = me.y + b.y};
fn Add[self: Point1](b: Point1) -> Point1 {
return {.x = self.x + b.x, .y = self.y + b.y};
}
fn Scale[me: Point1](v: i32) -> Point1 {
return {.x = me.x * v, .y = me.y * v};
fn Scale[self: Point1](v: i32) -> Point1 {
return {.x = self.x * v, .y = self.y * v};
}
}
}
@@ -31,11 +31,11 @@ class Point2 {
var x: i32;
var y: i32;
impl Point2 as Vector {
fn Add[me: Point2](b: Point2) -> Point2 {
return {.x = me.x + b.x + 1, .y = me.y + b.y + 1};
fn Add[self: Point2](b: Point2) -> Point2 {
return {.x = self.x + b.x + 1, .y = self.y + b.y + 1};
}
fn Scale[me: Point2](v: i32) -> Point2 {
return {.x = me.x * v * 2, .y = me.y * v * 2};
fn Scale[self: Point2](v: i32) -> Point2 {
return {.x = self.x * v * 2, .y = self.y * v * 2};
}
}
}
+4 -4
View File
@@ -11,12 +11,12 @@
package ExplorerTest api;
interface Apple(T:! Type) {
fn F[me: Self]() -> T;
fn F[self: Self]() -> T;
}
interface Banana {
impl as Apple(i32);
fn G[me: Self]();
fn G[self: Self]();
}
class Carrot {
@@ -24,11 +24,11 @@ class Carrot {
}
external impl Carrot as Apple(i32) {
fn F[me: Self]() -> i32 { return me.n; }
fn F[self: Self]() -> i32 { return self.n; }
}
external impl Carrot as Banana {
fn G[me: Self]() { Print("Carrot.G"); }
fn G[self: Self]() { Print("Carrot.G"); }
}
fn H[T:! Banana](x: T) -> i32 {
+1 -1
View File
@@ -21,7 +21,7 @@ class IntHolder {
var n: i32;
}
external impl i32 as ImplicitAs(IntHolder) {
fn Convert[me: Self]() -> IntHolder { return {.n = me}; }
fn Convert[self: Self]() -> IntHolder { return {.n = self}; }
}
external impl IntHolder as ConvertsFromInt {}
@@ -10,7 +10,7 @@
package ExplorerTest api;
interface MyAddWith(T:! Type) {
fn Op[me: Self](b: T) -> Self;
fn Op[self: Self](b: T) -> Self;
}
class Point {
@@ -20,8 +20,8 @@ class Point {
// Allowed: `Self` means `Point` after `as`
impl Point as MyAddWith(Self) {
fn Op[me: Point](b: Point) -> Point {
return {.x = me.x + b.x, .y = me.y + b.y};
fn Op[self: Point](b: Point) -> Point {
return {.x = self.x + b.x, .y = self.y + b.y};
}
}
+6 -6
View File
@@ -11,8 +11,8 @@ package ExplorerTest api;
interface Vector {
fn Zero() -> Self;
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 {
@@ -24,11 +24,11 @@ class Point {
fn Zero() -> Point {
return {.x = 0, .y = 0};
}
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};
}
}
}
@@ -10,11 +10,11 @@
package ExplorerTest api;
interface HasValueParam(T:! Type, V:! T) {
fn Go[me: Self]() -> T;
fn Go[self: Self]() -> T;
}
impl () as HasValueParam(i32, 5) {
fn Go[me: Self]() -> i32 { return 42; }
fn Go[self: Self]() -> i32 { return 42; }
}
fn Main() -> i32 {
+6 -6
View File
@@ -11,8 +11,8 @@ package ExplorerTest api;
interface Vector(Scalar:! Type) {
fn Zero() -> Self;
fn Add[me: Self](b: Self) -> Self;
fn Scale[me: Self](v: Scalar) -> Self;
fn Add[self: Self](b: Self) -> Self;
fn Scale[self: Self](v: Scalar) -> Self;
}
class Point {
@@ -22,11 +22,11 @@ class Point {
fn Zero() -> Point {
return {.x = 0, .y = 0};
}
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};
}
}
}
+6 -6
View File
@@ -10,19 +10,19 @@
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 {
var x: i32;
var y: i32;
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};
}
}
}
+6 -6
View File
@@ -10,19 +10,19 @@
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 {
var x: i32;
var y: i32;
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};
}
}
}
+6 -6
View File
@@ -11,8 +11,8 @@ package ExplorerTest api;
interface Vector {
fn Zero() -> Self;
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 {
@@ -23,11 +23,11 @@ class Point {
fn Zero() -> Self {
return {.x = 0, .y = 0};
}
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};
}
}
}