Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(ts/checker): Enable destructuringArrayBindingPatternAndAssignment3 #298

Conversation

Beraliv
Copy link
Contributor

@Beraliv Beraliv commented Nov 15, 2022

Description:

Given There are 2 tuples
 When lhs is tuple with `any` elements
  And rhs is tuple with different types
  And lhs is of higher length
 Then rhs is assignable to lhs

I simply ignore AssignFailedBecauseTupleLengthDiffers when there is a tuple with any elements for lhs.

The only regression is conformance::expressions::arrayLiterals::arrayLiterals3.ts where var a0: [any, any, any] = [] is PASSED without errors now (which is wrong).

Can you please recommend a way to distinguish tuple in parameters and tuple in variables?

But we will need to distinguish these cases in the future for sure:

var a0: [any, any, any] = [];  // ❌ error as tuple of length 0 is NOT assignable to tuple of length 3
var a1: [any?, any?, any?] = []; // ✅ ok, tuple of length 0 is assignable to tuple of length 0 up to 3

(function ([f, g, h, i]) { // ✅ ok, as [1] is number[] by default so here we have f: number, g: number; h: number; i: number
})([1]);
(function ([f, g = 1, h = 2, i = 3]) { // ✅ ok, same but with default parameters
})([1]);

Playground 🔗 – https://tsplay.dev/w8xO9w

BREAKING CHANGE:

Related issue (if exists): #181

add crates/stc_ts_file_analyzer/tests/pass/es6/destructuring/destructuri
ngArrayBindingPatternAndAssignment3/.6.ts
Added crates/stc_ts_file_analyzer/tests/pass/es6/destructuring/destructu
ringArrayBindingPatternAndAssignment3/.6.ts
@CLAassistant
Copy link

CLAassistant commented Nov 15, 2022

CLA assistant check
All committers have signed the CLA.

@Beraliv Beraliv marked this pull request as ready for review November 16, 2022 00:09
@@ -2067,6 +2067,18 @@ impl Analyzer<'_, '_> {
// TODO: Handle Type::Rest

if elems.len() > rhs_elems.len() {
let is_lhs_any_tuple = elems.iter().all(|l| match *l.ty {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I think we should leverage the optional type as you said in #181 (comment)

@kdy1 kdy1 enabled auto-merge (squash) November 24, 2022 09:46
@kdy1 kdy1 added this to the 1. Correctness milestone Nov 24, 2022
@kdy1 kdy1 merged commit 9363430 into dudykr:main Nov 24, 2022
@Beraliv Beraliv deleted the conformance/destructuringArrayBindingPatternAndAssignment3 branch November 24, 2022 10:44
@kdy1 kdy1 self-assigned this Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants