-
Notifications
You must be signed in to change notification settings - Fork 201
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): can't pass inflight closure as parameter to
super()
…
…call (#6599) fixes #4925 Now you can pass inflight closures and also any `new PreflightClass()` as parameters to a `super()` call in a ctor. What I did is detect these cases and made sure the implicit scope passed to the construct ctor is `$scope` and not `this` which isn't available before `super()` is called. ## Checklist - [x] Title matches [Winglang's style guide](https://www.winglang.io/contributing/start-here/pull_requests#how-are-pull-request-titles-formatted) - [x] Description explains motivation and solution - [x] Tests added (always) - [ ] Docs updated (only required for features) - [ ] Added `pr/e2e-full` label if this feature requires end-to-end testing *By submitting this pull request, I confirm that my contribution is made under the terms of the [Wing Cloud Contribution License](https://github.com/winglang/wing/blob/main/CONTRIBUTION_LICENSE.md)*.
- Loading branch information
1 parent
5ff5635
commit ccdd51b
Showing
9 changed files
with
480 additions
and
11 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
35 changes: 35 additions & 0 deletions
35
examples/tests/valid/inflight_closure_as_super_param.test.w
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,35 @@ | ||
class Foo {} | ||
|
||
class Base { | ||
pub h: inflight (): str; | ||
pub f_base: Foo; | ||
new(handler: inflight (): str, f: Foo) { | ||
this.h = handler; | ||
this.f_base = f; | ||
} | ||
} | ||
|
||
class Derived extends Base { | ||
pub f: Foo; | ||
new() { | ||
super(inflight (): str => { | ||
return "boom!"; | ||
}, new Foo() as "in_root"); | ||
this.f = new Foo() as "in_derived"; | ||
} | ||
} | ||
|
||
let c = new Derived() as "derived"; | ||
// Make sure that instances created in a ctor are scoped to the instance they were created in | ||
// This is related to this test because the transformed inflight closure is also an instance | ||
// created in a ctor, but it's special cased to to be scoped in the class because `this` isn't | ||
// available during the closures instantiation. | ||
assert(nodeof(c.f).path.endsWith("derived/in_derived")); | ||
// Make sure the instance created in the super call is scoped to the parent (root) | ||
assert(!nodeof(c.f_base).path.endsWith("derived/in_root")); | ||
let appPath = nodeof(this).path; | ||
assert(nodeof(c.f_base).path == "{appPath}/in_root"); | ||
|
||
test "boom!" { | ||
assert(c.h() == "boom!"); | ||
} |
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
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.