-
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.
fix(compiler)!: unexpected heuristic for inference across scopes (#4455)
Fixes #4438 Due to: - breadth-first type checking - simplistic inference - no re-checking (good) Currently, this works: ``` let f = (arg) => { return arg.get("a"); }; if true { let x = f({ a: true }); } ``` but this does not work: ``` let f = () => { return { a: true }; }; if true { let x = f().get("a"); // ^^^ don't know what the return type is yet because the closure above hasn't be checked } ``` Because when first implementing inference, the sub-scopes of a scope were checked in reverse order. I thought this heuristic was kinda neat and figured it had legs. Now I'm thinking that was wrong. With this PR, the scope will be checked in normal order. Now the second case will work and the first case above will **not** work. It will require explicit annotation on the argument: ``` let f = (arg: Json) => { return arg.get("a"); }; if true { let x = f({ a: true }); } ``` *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)*. BREAKING CHANGE: Inference now prioritizes earlier scopes rather than later ones. This previously allowed closures called from other scopes to leave off argument type annotations. [This](https://github.com/winglang/wing/blob/fcfc3462d37a063d96d49b4105e27466ff7793c8/examples/tests/invalid/inference.test.w#L106) is an example of a case that previously worked.
- Loading branch information
1 parent
31c8698
commit 8b6f604
Showing
6 changed files
with
241 additions
and
172 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
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.