-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,196 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
class A { | ||
method() { | ||
// Acccess super with no base class (in case of preflight there's actually an implicit base class, `std.Resource`, we need to ignore) | ||
super.method(); | ||
//^^^^^^ Cannot call super method because class A has no parent | ||
} | ||
} | ||
|
||
inflight class InflightA { | ||
method() { | ||
// Access super with no base class | ||
super.method(); | ||
//^^^^^^ Cannot call super method because class A has no parent | ||
} | ||
} | ||
|
||
class B extends A { | ||
child_method() { | ||
// Access child method through super | ||
super.child_method(); | ||
//^^^^^^^^^^^^ super class "A" does not have a method named "child_method" | ||
} | ||
|
||
static static_method() { | ||
// super doesn't make sense in static context | ||
super.method(); | ||
//^^^^^ Cannot call super method inside of a static method | ||
} | ||
} | ||
|
||
// super doesn't make sense in global context | ||
super.do(); | ||
//^^ "super" can only be used inside of classes | ||
|
||
|
||
// Verify correct error message when inflight closure tries to access super (this isn't suported yet see: https://github.com/winglang/wing/issues/3474) | ||
// Once it is, this test should be moved to "valid" | ||
class BaseClass { | ||
inflight m1(): str { | ||
return "base inflight m1"; | ||
} | ||
} | ||
|
||
bring cloud; | ||
let q = new cloud.Queue(); | ||
class ExtendedClass extends BaseClass { | ||
inflight m1(): str { | ||
return "extended inflight m1"; | ||
} | ||
get_func(): cloud.Function { | ||
let inflight_closure = inflight (s:str): str => { | ||
return "this: ${this.m1()}, super: ${super.m1()}"; | ||
//^^ `super` calls inside inflight closures not supported yet, see: https://github.com/winglang/wing/issues/3474 | ||
}; | ||
return new cloud.Function(inflight_closure); | ||
} | ||
} | ||
// TODO: uncomment and move to valid tests once this: https://github.com/winglang/wing/issues/3474 is fixed | ||
// let y = new ExtendedClass().get_func(); | ||
// test "inflight closure accesses super" { | ||
// assert(y.invoke("") == "this: extended inflight m1, super: base inflight m1"); | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
class A { | ||
message: str; | ||
|
||
init() { | ||
this.message = "A message from your ancestor"; | ||
} | ||
} | ||
|
||
class B extends A { | ||
description(): str { | ||
return "B"; | ||
} | ||
} | ||
|
||
class C extends B { | ||
description(): str { | ||
return "C extends ${super.description()}"; | ||
} | ||
} | ||
|
||
// This class has no `description` method, so it inherits the one from `B`. | ||
class D extends C { | ||
} | ||
|
||
class E extends D { | ||
description(): str { | ||
return "E extends ${super.description()}"; | ||
} | ||
} | ||
|
||
let e = new E(); | ||
// Make sure super calls work and skip anything in the inheritance chain that doesn't have the method | ||
assert(e.description() == "E extends C extends B"); | ||
|
||
inflight class InflightA { | ||
description(): str { | ||
return "InflightA"; | ||
} | ||
} | ||
|
||
// Test super calls on inflight classes | ||
inflight class InflightB extends InflightA { | ||
description(): str { | ||
return "InflightB extends ${super.description()}"; | ||
} | ||
} | ||
|
||
test "super call inflight" { | ||
let b = new InflightB(); | ||
assert(b.description() == "InflightB extends InflightA"); | ||
} | ||
|
||
// Test correct binding when calling a super method | ||
bring cloud; | ||
let b = new cloud.Bucket(); | ||
class BaseClass { | ||
inflight do(): str { | ||
return b.get("k"); // BaseClass class required read acceess to b | ||
} | ||
} | ||
|
||
class ExtendedClass extends BaseClass { | ||
inflight do(): str { | ||
b.put("k", "value"); // This should require write access to b | ||
return super.do(); // We expect to add binding permissions based on what `super.do()` requires (read) | ||
} | ||
} | ||
|
||
let extended = new ExtendedClass(); | ||
test "super call sets binding permissions" { | ||
assert(extended.do() == "value"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.