-
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): mutable lifted object may be modified inflight (#6258)
fixes #3069 The type checker will now modify the type of preflight expressions that are being used inflight to a non-mutable version of the same type: `MutArray` -> `Array`, `MutJson` -> `Json`... Note that since we change the type of the expression we don't get descriptive error telling us that we're trying to mutate a lifted mutable object, instead we just get the same error we'd expect if the lifted object was non-mutable to begin with. This isn't ideal but it makes the fix simpler. Let me know what you think... ## 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) - [x] 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
0e1222f
commit d867af8
Showing
4 changed files
with
126 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
let ar = MutArray<num>[]; | ||
ar.push(1); | ||
|
||
let j = MutJson {a: 1}; | ||
j.set("a", 2); | ||
|
||
let st = MutSet<num>[1,2]; | ||
st.add(3); | ||
|
||
let mp = MutMap<num>{"a" => 1}; | ||
mp.set("a", 2); | ||
|
||
let opt_ar: MutArray<num>? = MutArray<num>[]; | ||
opt_ar?.push(1); | ||
|
||
let recursive_ar = MutArray<MutArray<num>>[]; | ||
recursive_ar.push(MutArray<num>[1]); | ||
recursive_ar.at(0).push(2); | ||
|
||
inflight() => { | ||
// Same code as above should be an error in inflight | ||
ar.push(2); // Error: push doesn't exist in Array | ||
ar[0] = 1; // Error: Cannot update elements of an immutable Array | ||
j.set("a", 3); // Error: set doesn't exist in Json | ||
st.add(4); // Error: add doesn't exist in Set | ||
mp.set("a", 3); // Error: set doesn't exist in Map | ||
opt_ar?.push(2); // Error: push doesn't exist in Array | ||
recursive_ar.push(MutArray<num>[2]); // Error: push doesn't exist in Array | ||
recursive_ar.at(0).push(3); // Error: push doesn't exist in Array | ||
}; |
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