-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(compiler): expected type to be "Array", but got "Array" instead (#…
…6571) Fixes #3822 I considered a few approaches and concluded that the lightest one would be passing the parent type into the validation function, and then using it (if not None) in the diagnostic message. Updated the validation function calls accordingly. Currently supported only for the `Equal` and `NotEqual` binary operators ## 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
Showing
3 changed files
with
282 additions
and
16 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,79 @@ | ||
// arrays | ||
|
||
assert([{a: 1}] == [{a: 1}]); | ||
|
||
assert(MutArray<Json>[{a: 1}] == Array<Json>[MutJson{a: 1}]); | ||
// this is fine- we ignore mutable | ||
|
||
assert([1,2] == ["a", "b"]); | ||
// ^^^^^^^^^^^^^^^^^^^ Expected type to be "Array<num>", but got "Array<str>" instead | ||
|
||
assert(["a", "b"] == [1,2]); | ||
// ^^^^^^^^^^^^^^^^^^^ Expected type to be "Array<str>", but got "Array<num>" instead | ||
|
||
assert([{a: 1}] == ["1", "2"]); | ||
//this doesn't throw an error since string is a subtype of json | ||
|
||
|
||
assert(["1", "2"] == [{a: 1}]); | ||
// ^^^^^^^^^^^^^^^^^^^^^^ Expected type to be "Array<str>", but got "Array<Json>" instead | ||
|
||
assert([["1", "2"]] == [[{a: 1}]]); | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected type to be "Array<Array<str>>", but got "Array<Array<Json>>" instead | ||
|
||
assert({"a" => ["a"]} == {"a" => [1]}); | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected type to be "Map<Array<str>>", but got "Map<Array<num>>" instead | ||
|
||
assert([{"a" => [1]}] == [{"a" => ["a"]}]); | ||
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Expected type to be "Array<Map<Array<num>>>", but got "Array<Map<Array<str>>>" instead | ||
|
||
let a1: Array<bool>? = nil; | ||
let a2: Array<str>? = nil; | ||
|
||
assert(a1 == a2); | ||
// ^^^^^^^^ Expected type to be "Array<bool>?", but got "Array<str>?" instead | ||
|
||
let b1: Array<str> = []; | ||
let b2: Array<str>? = []; | ||
|
||
assert(b1 == b2); | ||
// ^^^^^^^^ Expected type to be "Array<str>", but got "Array<str>?" instead | ||
|
||
assert([nil] == ["a"]); | ||
// ^^^^^^^^^^^^^^ Expected type to be "Array<nil>", but got "Array<str>" instead | ||
|
||
assert(Array<Json>[nil] == ["a"]); | ||
// ^^^ Expected type to be "Json", but got "nil" instead. hint: to allow "nil" assignment use optional type: "Json?" | ||
|
||
assert(Array<Json?>[nil] == ["a"]); | ||
// this is ok | ||
|
||
|
||
let c1: num? = nil; | ||
let c2: str? = nil; | ||
assert([c1] == [c2]); | ||
// ^^^^^^^^^^^^ Expected type to be "Array<num?>", but got "Array<str?>" instead | ||
|
||
|
||
assert([[1]] == [["1"]]); | ||
// ^^^^^^^^^^^^^^^^ Expected type to be "Array<Array<num>>", but got "Array<Array<str>>" instead | ||
|
||
assert([["1"]] == [[1]]); | ||
// ^^^^^^^^^^^^^^^^ Expected type to be "Array<Array<str>>", but got "Array<Array<num>>" instead | ||
|
||
let d1 = {"a" => 1}; | ||
let d2 = {"b" => "b"}; | ||
assert(d1 == d2); | ||
// ^^^^^^^^ Expected type to be "Map<num>", but got "Map<str>" instead | ||
|
||
let e1 = MutSet<bool>[true, true, true]; | ||
let e2 = Set<num>[1,2,3,3,3,2]; | ||
|
||
assert(e1 == e2); | ||
// ^^^^^^^^ Expected type to be "MutSet<bool>", but got "Set<num>" instead | ||
|
||
let f1 = Set<num>[1,2,3,3,3,2]; | ||
let f2 = MutSet<num>[1,2,3,3,3,2]; | ||
|
||
assert(f1 == f2); | ||
// this is ok |
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