From 370071bc6ce119331c63bca1dc904b8f2108fd9c Mon Sep 17 00:00:00 2001 From: devgony Date: Sat, 14 Jan 2023 20:51:02 +0900 Subject: [PATCH 01/33] feat: implement interface array case --- .../src/analyzer/assign/mod.rs | 1 + .../src/analyzer/types/mod.rs | 39 ++++++++++++++++--- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index ac99b93b1a..3a587c1a2c 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -535,6 +535,7 @@ impl Analyzer<'_, '_> { op: TsTypeOperatorOp::KeyOf, .. }) + | Type::Interface(..) | Type::Tpl(..) => { let ty = self .normalize( diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 60ae786608..681a7fb61f 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -16,10 +16,10 @@ use stc_ts_generics::ExpandGenericOpts; use stc_ts_type_ops::{tuple_normalization::TupleNormalizer, Fix}; use stc_ts_types::{ name::Name, Accessor, Array, Class, ClassDef, ClassMember, ClassMetadata, ComputedKey, Conditional, ConditionalMetadata, - ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Intersection, - IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, Operator, PropertySignature, - QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, TypeLit, TypeLitMetadata, - TypeParam, TypeParamInstantiation, Union, + ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Interface, + InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, + Operator, PropertySignature, QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, + TypeLit, TypeLitMetadata, TypeParam, TypeParamInstantiation, Union, }; use stc_ts_utils::run; use stc_utils::{ @@ -108,7 +108,6 @@ impl Analyzer<'_, '_> { match ty.normalize() { Type::Lit(..) | Type::TypeLit(..) - | Type::Interface(..) | Type::Class(..) | Type::ClassDef(..) | Type::Tuple(..) @@ -117,6 +116,36 @@ impl Analyzer<'_, '_> { | Type::EnumVariant(..) | Type::Param(_) | Type::Module(_) => return Ok(ty), + Type::Interface(Interface { + span, + name, + type_params, + extends, + body, + metadata: InterfaceMetadata { common }, + tracker, + }) => { + for extend in extends { + let types = extend.to_owned().type_args.into_iter().flat_map(|cur| cur.params); + let union_type = Type::new_union(*span, types); + if let box RExpr::Ident(ident) = &extend.expr { + let RIdent { + node_id, + span, + sym, + optional, + } = ident; + if sym == &js_word!("Array") { + return Ok(Cow::Owned(Type::Array(Array { + span: *span, + elem_type: box union_type, + metadata: Default::default(), + tracker: Default::default(), + }))); + }; + }; + } + } _ => {} } From ce4cf984bf30b77970c82b543b612ec6fcfa44d8 Mon Sep 17 00:00:00 2001 From: devgony Date: Sat, 14 Jan 2023 21:33:04 +0900 Subject: [PATCH 02/33] fix: filter array by `type_of_ts_entity_name` --- .../src/analyzer/types/mod.rs | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 681a7fb61f..b5a0ac92b6 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -125,25 +125,11 @@ impl Analyzer<'_, '_> { metadata: InterfaceMetadata { common }, tracker, }) => { - for extend in extends { - let types = extend.to_owned().type_args.into_iter().flat_map(|cur| cur.params); - let union_type = Type::new_union(*span, types); - if let box RExpr::Ident(ident) = &extend.expr { - let RIdent { - node_id, - span, - sym, - optional, - } = ident; - if sym == &js_word!("Array") { - return Ok(Cow::Owned(Type::Array(Array { - span: *span, - elem_type: box union_type, - metadata: Default::default(), - tracker: Default::default(), - }))); - }; - }; + for parent in extends { + let parent = self.type_of_ts_entity_name(parent.span(), &parent.expr, parent.type_args.as_deref())?; + if let Type::Array(_) = &parent { + return Ok(Cow::Owned(parent)); + } } } _ => {} From fc489815ae61734ce47019e0e350bd924ce74507 Mon Sep 17 00:00:00 2001 From: devgony Date: Wed, 1 Feb 2023 17:12:13 +0900 Subject: [PATCH 03/33] temp-1 --- crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs | 2 +- .../types/tuple/arityAndOrderCompatibility01.stats.rust-debug | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index b5a0ac92b6..99d20a7fe5 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -127,7 +127,7 @@ impl Analyzer<'_, '_> { }) => { for parent in extends { let parent = self.type_of_ts_entity_name(parent.span(), &parent.expr, parent.type_args.as_deref())?; - if let Type::Array(_) = &parent { + if let Type::Array(_) | Type::Tpl(_) = &parent { return Ok(Cow::Owned(parent)); } } diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug index ebb9a372e6..1ccdc28654 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 2, matched_error: 15, - extra_error: 6, + extra_error: 5, panic: 0, } \ No newline at end of file From 71cefdddc4db6800eb4d6a43eefe95020fd9e0dc Mon Sep 17 00:00:00 2001 From: devgony Date: Wed, 1 Feb 2023 18:00:51 +0900 Subject: [PATCH 04/33] fix: implement handling interface at `assign/mod.rs` --- .../src/analyzer/assign/mod.rs | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 5b673244d4..2141354578 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -7,9 +7,9 @@ use stc_ts_errors::{ }; use stc_ts_file_analyzer_macros::context; use stc_ts_types::{ - Array, Conditional, EnumVariant, IdCtx, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, - LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, Type, TypeElement, - TypeLit, TypeParam, + Array, Conditional, EnumVariant, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, + KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, + Type, TypeElement, TypeLit, TypeParam, }; use stc_utils::{cache::Freeze, stack}; use swc_atoms::js_word; @@ -1410,7 +1410,6 @@ impl Analyzer<'_, '_> { .assign_with_opts(data, ty, rhs, opts) .context("tried to assign a type to an operand of readonly type") } - _ => {} } @@ -1421,6 +1420,22 @@ impl Analyzer<'_, '_> { } match rhs { + Type::Interface(Interface { + span, + name, + type_params, + extends, + body, + metadata: InterfaceMetadata { common }, + tracker, + }) => { + for parent in extends { + let ty = self.type_of_ts_entity_name(parent.span(), &parent.expr, parent.type_args.as_deref())?; + if let Type::Array(_) = &ty { + return self.assign_with_opts(data, &ty, rhs, opts); + } + } + } Type::Ref(..) => { let mut new_rhs = self.expand_top_ref(span, Cow::Borrowed(rhs), Default::default())?; new_rhs.freeze(); From 96f45673195d86755121be378310438e5c5244ec Mon Sep 17 00:00:00 2001 From: devgony Date: Wed, 1 Feb 2023 18:03:46 +0900 Subject: [PATCH 05/33] fix: remove previous implement --- .../src/analyzer/types/mod.rs | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 4866c11bb9..3235b9fc48 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -114,22 +114,7 @@ impl Analyzer<'_, '_> { | Type::EnumVariant(..) | Type::Param(_) | Type::Module(_) => return Ok(ty), - Type::Interface(Interface { - span, - name, - type_params, - extends, - body, - metadata: InterfaceMetadata { common }, - tracker, - }) => { - for parent in extends { - let parent = self.type_of_ts_entity_name(parent.span(), &parent.expr, parent.type_args.as_deref())?; - if let Type::Array(_) | Type::Tpl(_) = &parent { - return Ok(Cow::Owned(parent)); - } - } - } + _ => {} } From f27ad7e8abda742c215ad6e413c30ccb1aacd6e3 Mon Sep 17 00:00:00 2001 From: devgony Date: Wed, 1 Feb 2023 18:05:23 +0900 Subject: [PATCH 06/33] fix: remove imports --- crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 3235b9fc48..2c6d48cb96 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -16,10 +16,10 @@ use stc_ts_generics::ExpandGenericOpts; use stc_ts_type_ops::{tuple_normalization::normalize_tuples, Fix}; use stc_ts_types::{ name::Name, Accessor, Array, Class, ClassDef, ClassMember, ClassMetadata, ComputedKey, Conditional, ConditionalMetadata, - ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Interface, - InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, - Operator, PropertySignature, QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, - TypeLit, TypeLitMetadata, TypeParam, TypeParamInstantiation, Union, + ConstructorSignature, EnumVariant, FnParam, Id, IdCtx, IndexSignature, IndexedAccessType, Instance, InstanceMetadata, Intersection, + IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, LitTypeMetadata, MethodSignature, Operator, PropertySignature, + QueryExpr, QueryType, Ref, StringMapping, ThisType, ThisTypeMetadata, TplElem, TplType, Type, TypeElement, TypeLit, TypeLitMetadata, + TypeParam, TypeParamInstantiation, Union, }; use stc_ts_utils::run; use stc_utils::{ From 43f4aec75751510d6e7d2415c46ecb4407d98913 Mon Sep 17 00:00:00 2001 From: devgony Date: Wed, 1 Feb 2023 18:07:51 +0900 Subject: [PATCH 07/33] chore: remove redundant diff --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 1 - crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 151c2000b0..2141354578 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -540,7 +540,6 @@ impl Analyzer<'_, '_> { op: TsTypeOperatorOp::KeyOf, .. }) - | Type::Interface(..) | Type::Tpl(..) => { let ty = self .normalize( diff --git a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs index 2c6d48cb96..a5edf6e0fc 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/types/mod.rs @@ -107,6 +107,7 @@ impl Analyzer<'_, '_> { match ty.normalize() { Type::Lit(..) | Type::TypeLit(..) + | Type::Interface(..) | Type::Class(..) | Type::ClassDef(..) | Type::Function(..) @@ -114,7 +115,6 @@ impl Analyzer<'_, '_> { | Type::EnumVariant(..) | Type::Param(_) | Type::Module(_) => return Ok(ty), - _ => {} } From 20f45138ccd1d7a8d10ee474e3ec036e87d42d70 Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 08:20:57 +0900 Subject: [PATCH 08/33] fix: compare types of lhs and rhs --- .../src/analyzer/assign/mod.rs | 103 ++++++++++++++++-- 1 file changed, 94 insertions(+), 9 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 2141354578..42ddec3880 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -8,8 +8,8 @@ use stc_ts_errors::{ use stc_ts_file_analyzer_macros::context; use stc_ts_types::{ Array, Conditional, EnumVariant, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, - KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, - Type, TypeElement, TypeLit, TypeParam, + KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, + TsExpr, Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, }; use stc_utils::{cache::Freeze, stack}; use swc_atoms::js_word; @@ -1031,6 +1031,51 @@ impl Analyzer<'_, '_> { return Ok(()); } + ( + Type::Tuple(Tuple { + span: tspan, + elems, + metadata, + tracker, + }), + Type::Interface(Interface { + span: ispan, + name, + type_params, + extends, + body, + metadata: imetadata, + tracker: itracker, + }), + ) => { + let lhs = elems.iter().map(|TupleElement { span, label, ty, tracker }| ty); + for parent in extends { + let params = parent.type_args.clone().unwrap().params; + let rhs = self + .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? + .freezed(); + match rhs { + Type::Array(_) | Type::Tuple(_) | Type::Tpl(_) => { + for (a, b) in lhs.clone().zip(params) { + self.assign_with_opts(data, a, &b, opts).context("%%%%test context")?; + } + } + _ => {} + } + } + + return Ok(()); + // let tys2 = extends.iter().map(|parent| { + // self.type_of_ts_entity_name(span, &parent.expr, + // parent.type_args.as_deref()) + // .unwrap() + // .freezed() + // }); + // for (a, b) in tys.zip(tys2) { + // self.assign_with_opts(data, a, &b, opts) + // .context("tried to assign to the true type")?; + // } + } _ => {} } @@ -1421,20 +1466,60 @@ impl Analyzer<'_, '_> { match rhs { Type::Interface(Interface { - span, + // span, name, type_params, extends, body, metadata: InterfaceMetadata { common }, tracker, + .. }) => { - for parent in extends { - let ty = self.type_of_ts_entity_name(parent.span(), &parent.expr, parent.type_args.as_deref())?; - if let Type::Array(_) = &ty { - return self.assign_with_opts(data, &ty, rhs, opts); - } - } + // for parent in extends { + // let ty = self.type_of_ts_entity_name(parent.span(), + // &parent.expr, parent.type_args.as_deref())?; + // if let Type::Array(_) | Type::Tpl(_) = &ty { + // return self.assign_with_opts(data, &ty, rhs, + // opts); } } + + // let mut errors = vec![]; + // for parent in extends { + // let parent = self + // .type_of_ts_entity_name(span, &parent.expr, + // parent.type_args.as_deref())? .freezed(); + + // // An interface can extend a class. + // let parent = self.instantiate_class(span, &parent)?; + + // let res = self.assign_with_opts( + // data, + // &parent, + // rhs, + // AssignOpts { + // allow_unknown_rhs: Some(true), + // ..opts + // }, + // ); + + // errors.extend(res.err()); + // } + + // if !extends.is_empty() && errors.is_empty() { + // return Ok(()); + // } + + // if !errors.is_empty() { + // return Err(ErrorKind::AssignFailed { + // span, + // left: box to.clone(), + // right: box rhs.clone(), + // right_ident: opts.right_ident_span, + // cause: errors, + // } + // .into()); + // } + + // return Ok(()); } Type::Ref(..) => { let mut new_rhs = self.expand_top_ref(span, Cow::Borrowed(rhs), Default::default())?; From bd11c05a43eb4bbc8f9e30438dea1720de44f693 Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 13:12:42 +0900 Subject: [PATCH 09/33] fix: zip and iterate each lkind and rkind --- .../src/analyzer/assign/mod.rs | 47 ++++++++++--------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 42ddec3880..9a4a684a9a 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -2,14 +2,14 @@ use std::{borrow::Cow, collections::HashMap}; use stc_ts_ast_rnode::{RBool, RExpr, RIdent, RLit, RNumber, RStr, RTsEntityName, RTsEnumMemberId, RTsLit}; use stc_ts_errors::{ - debug::{dump_type_as_string, force_dump_type_as_string}, + debug::{dump_type_as_string, force_dump_type_as_string, print_backtrace}, DebugExt, ErrorKind, }; use stc_ts_file_analyzer_macros::context; use stc_ts_types::{ - Array, Conditional, EnumVariant, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, + Array, Conditional, EnumVariant, Freezed, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, - TsExpr, Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, + TsExpr, Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, Union, }; use stc_utils::{cache::Freeze, stack}; use swc_atoms::js_word; @@ -1054,27 +1054,32 @@ impl Analyzer<'_, '_> { let rhs = self .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? .freezed(); - match rhs { - Type::Array(_) | Type::Tuple(_) | Type::Tpl(_) => { - for (a, b) in lhs.clone().zip(params) { - self.assign_with_opts(data, a, &b, opts).context("%%%%test context")?; + if let Some(Array { + span, + elem_type, + metadata, + tracker, + }) = rhs.array() + { + if let Some(Union { + span, + types, + metadata, + tracker, + }) = elem_type.union_type() + { + for (lhs, ty) in lhs.clone().zip(types) { + if let (Some(KeywordType { kind: lkind, .. }), Some(KeywordType { kind: rkind, .. })) = + (lhs.to_owned().keyword(), ty.keyword()) + { + println!("@@@\n{lkind:#?}:{rkind:#?}"); + let diff = lkind == rkind; + println!("@@@\n{diff}"); + } } } - _ => {} - } + }; } - - return Ok(()); - // let tys2 = extends.iter().map(|parent| { - // self.type_of_ts_entity_name(span, &parent.expr, - // parent.type_args.as_deref()) - // .unwrap() - // .freezed() - // }); - // for (a, b) in tys.zip(tys2) { - // self.assign_with_opts(data, a, &b, opts) - // .context("tried to assign to the true type")?; - // } } _ => {} } From 259c3742fc9857aa8a1909be7a18fd61cd2e808c Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 13:46:19 +0900 Subject: [PATCH 10/33] fix: early return `assign_with_opts` --- .../src/analyzer/assign/mod.rs | 72 ++----------------- 1 file changed, 7 insertions(+), 65 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 9a4a684a9a..537aa075c6 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -2,14 +2,14 @@ use std::{borrow::Cow, collections::HashMap}; use stc_ts_ast_rnode::{RBool, RExpr, RIdent, RLit, RNumber, RStr, RTsEntityName, RTsEnumMemberId, RTsLit}; use stc_ts_errors::{ - debug::{dump_type_as_string, force_dump_type_as_string, print_backtrace}, + debug::{dump_type_as_string, force_dump_type_as_string}, DebugExt, ErrorKind, }; use stc_ts_file_analyzer_macros::context; use stc_ts_types::{ - Array, Conditional, EnumVariant, Freezed, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, - KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, - TsExpr, Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, Union, + Array, Conditional, EnumVariant, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, + KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, + TupleElement, Type, TypeElement, TypeLit, TypeParam, Union, }; use stc_utils::{cache::Freeze, stack}; use swc_atoms::js_word; @@ -1068,13 +1068,11 @@ impl Analyzer<'_, '_> { tracker, }) = elem_type.union_type() { - for (lhs, ty) in lhs.clone().zip(types) { + for (lhs, rhs) in lhs.clone().zip(types) { if let (Some(KeywordType { kind: lkind, .. }), Some(KeywordType { kind: rkind, .. })) = - (lhs.to_owned().keyword(), ty.keyword()) + (lhs.to_owned().keyword(), rhs.clone().keyword()) { - println!("@@@\n{lkind:#?}:{rkind:#?}"); - let diff = lkind == rkind; - println!("@@@\n{diff}"); + return self.assign_with_opts(data, lhs, &rhs, opts); } } } @@ -1470,62 +1468,6 @@ impl Analyzer<'_, '_> { } match rhs { - Type::Interface(Interface { - // span, - name, - type_params, - extends, - body, - metadata: InterfaceMetadata { common }, - tracker, - .. - }) => { - // for parent in extends { - // let ty = self.type_of_ts_entity_name(parent.span(), - // &parent.expr, parent.type_args.as_deref())?; - // if let Type::Array(_) | Type::Tpl(_) = &ty { - // return self.assign_with_opts(data, &ty, rhs, - // opts); } } - - // let mut errors = vec![]; - // for parent in extends { - // let parent = self - // .type_of_ts_entity_name(span, &parent.expr, - // parent.type_args.as_deref())? .freezed(); - - // // An interface can extend a class. - // let parent = self.instantiate_class(span, &parent)?; - - // let res = self.assign_with_opts( - // data, - // &parent, - // rhs, - // AssignOpts { - // allow_unknown_rhs: Some(true), - // ..opts - // }, - // ); - - // errors.extend(res.err()); - // } - - // if !extends.is_empty() && errors.is_empty() { - // return Ok(()); - // } - - // if !errors.is_empty() { - // return Err(ErrorKind::AssignFailed { - // span, - // left: box to.clone(), - // right: box rhs.clone(), - // right_ident: opts.right_ident_span, - // cause: errors, - // } - // .into()); - // } - - // return Ok(()); - } Type::Ref(..) => { let mut new_rhs = self.expand_top_ref(span, Cow::Borrowed(rhs), Default::default())?; new_rhs.freeze(); From 5928792a6b13834d5e5253da995acad2e82b2881 Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 13:47:23 +0900 Subject: [PATCH 11/33] chore: remove unused import --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 537aa075c6..375af8b3f1 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -7,9 +7,9 @@ use stc_ts_errors::{ }; use stc_ts_file_analyzer_macros::context; use stc_ts_types::{ - Array, Conditional, EnumVariant, IdCtx, Instance, Interface, InterfaceMetadata, Intersection, IntrinsicKind, Key, KeywordType, - KeywordTypeMetadata, LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, - TupleElement, Type, TypeElement, TypeLit, TypeParam, Union, + Array, Conditional, EnumVariant, IdCtx, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, + LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, TupleElement, Type, + TypeElement, TypeLit, TypeParam, Union, }; use stc_utils::{cache::Freeze, stack}; use swc_atoms::js_word; From 2e880cb35825d9f7730ede5d7a2a1758c08269ef Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 13:50:49 +0900 Subject: [PATCH 12/33] fix: remove unused params --- .../src/analyzer/assign/mod.rs | 22 ++++--------------- 1 file changed, 4 insertions(+), 18 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 375af8b3f1..250171d12e 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1048,30 +1048,16 @@ impl Analyzer<'_, '_> { tracker: itracker, }), ) => { - let lhs = elems.iter().map(|TupleElement { span, label, ty, tracker }| ty); + let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); for parent in extends { let params = parent.type_args.clone().unwrap().params; let rhs = self .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? .freezed(); - if let Some(Array { - span, - elem_type, - metadata, - tracker, - }) = rhs.array() - { - if let Some(Union { - span, - types, - metadata, - tracker, - }) = elem_type.union_type() - { + if let Some(Array { elem_type, .. }) = rhs.array() { + if let Some(Union { types, .. }) = elem_type.union_type() { for (lhs, rhs) in lhs.clone().zip(types) { - if let (Some(KeywordType { kind: lkind, .. }), Some(KeywordType { kind: rkind, .. })) = - (lhs.to_owned().keyword(), rhs.clone().keyword()) - { + if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { return self.assign_with_opts(data, lhs, &rhs, opts); } } From 135e2b3f444cd2b63c06ec0c4e982703eccdaa9d Mon Sep 17 00:00:00 2001 From: devgony Date: Tue, 7 Feb 2023 13:54:25 +0900 Subject: [PATCH 13/33] fix: remove wrong spell --- .../src/analyzer/assign/mod.rs | 18 +----------------- 1 file changed, 1 insertion(+), 17 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 250171d12e..c2c11813f1 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1031,23 +1031,7 @@ impl Analyzer<'_, '_> { return Ok(()); } - ( - Type::Tuple(Tuple { - span: tspan, - elems, - metadata, - tracker, - }), - Type::Interface(Interface { - span: ispan, - name, - type_params, - extends, - body, - metadata: imetadata, - tracker: itracker, - }), - ) => { + (Type::Tuple(Tuple { elems, .. }), Type::Interface(Interface { extends, .. })) => { let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); for parent in extends { let params = parent.type_args.clone().unwrap().params; From bba28d3c7a9c4b71fb457d132b34a8c3fe194f31 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 23 Mar 2023 22:54:44 +0900 Subject: [PATCH 14/33] fix: thanks clippy --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 9b8f9af3fc..f30c20f51f 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -6,12 +6,9 @@ use stc_ts_errors::{ DebugExt, ErrorKind, }; use stc_ts_types::{ - Array, Conditional, EnumVariant, IdCtx, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, - LitType, Mapped, Operator, PropertySignature, QueryExpr, QueryType, Ref, RestType, StringMapping, ThisType, Tuple, TupleElement, Type, - TypeElement, TypeLit, TypeParam, Union, Array, Conditional, EnumVariant, Index, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, - TypeElement, TypeLit, TypeParam, + TypeElement, TypeLit, TypeParam, Union, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; From 7e87f8efba0a85ea6f160a27f18ce65fe2f02947 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 19 May 2023 15:35:53 +0900 Subject: [PATCH 15/33] style: cargo fmt --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 71bee14af9..88b14f5eda 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -9,9 +9,6 @@ use stc_ts_types::{ Array, Conditional, EnumVariant, Index, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, Union, - Array, Conditional, EnumVariant, Index, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, LitType, Mapped, - PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, TypeLit, - TypeParam, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; From 78011c1530415c788812a68ad6ea5cc201d7fb1b Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 19 May 2023 17:20:26 +0900 Subject: [PATCH 16/33] style: thanks clippy --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 88b14f5eda..5659df881c 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -6,9 +6,9 @@ use stc_ts_errors::{ DebugExt, ErrorKind, }; use stc_ts_types::{ - Array, Conditional, EnumVariant, Index, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, KeywordTypeMetadata, - LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, - TypeElement, TypeLit, TypeParam, Union, + Array, Conditional, EnumVariant, Index, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, LitType, Mapped, + PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, TypeLit, + TypeParam, Union, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; From 4976748ed2bbd21cb741bba9dacccf77d0c1e08f Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 3 Jun 2023 21:56:49 +0900 Subject: [PATCH 17/33] test: add a case that should pass --- .../src/analyzer/assign/mod.rs | 37 ++++++++++--------- ...ityAndOrderCompatibility01.error-diff.json | 12 ++++++ ...tyAndOrderCompatibility01.stats.rust-debug | 2 +- .../tuple/arityAndOrderCompatibility01.ts | 25 ++++++++----- .../tests/tsc-stats.rust-debug | 8 ++-- 5 files changed, 52 insertions(+), 32 deletions(-) create mode 100644 crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.error-diff.json diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index ac59ffc814..68006054b9 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1121,24 +1121,24 @@ impl Analyzer<'_, '_> { return Ok(()); } - (Type::Tuple(Tuple { elems, .. }), Type::Interface(Interface { extends, .. })) => { - let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); - for parent in extends { - let params = parent.type_args.clone().unwrap().params; - let rhs = self - .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? - .freezed(); - if let Some(Array { elem_type, .. }) = rhs.array() { - if let Some(Union { types, .. }) = elem_type.union_type() { - for (lhs, rhs) in lhs.clone().zip(types) { - if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { - return self.assign_with_opts(data, lhs, &rhs, opts); - } - } - } - }; - } - } + // (Type::Tuple(Tuple { elems, .. }), Type::Interface(Interface { extends, .. })) => { + // let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); + // for parent in extends { + // let params = parent.type_args.clone().unwrap().params; + // let rhs = self + // .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? + // .freezed(); + // if let Some(Array { elem_type, .. }) = rhs.array() { + // if let Some(Union { types, .. }) = elem_type.union_type() { + // for (lhs, rhs) in lhs.clone().zip(types) { + // if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { + // return self.assign_with_opts(data, lhs, &rhs, opts); + // } + // } + // } + // }; + // } + // } _ => {} } @@ -1505,6 +1505,7 @@ impl Analyzer<'_, '_> { .assign_with_opts(data, ty, rhs, opts) .context("tried to assign a type to an operand of readonly type") } + _ => {} } diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.error-diff.json new file mode 100644 index 0000000000..7d2d308f28 --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.error-diff.json @@ -0,0 +1,12 @@ +{ + "required_errors": {}, + "required_error_lines": {}, + "extra_errors": { + "TS2322": 1 + }, + "extra_error_lines": { + "TS2322": [ + 39 + ] + } +} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug index 600f0901ff..f53c5e9395 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, matched_error: 17, - extra_error: 0, + extra_error: 1, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts index 85a035d472..b577eb0f04 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts @@ -1,16 +1,16 @@ -interface StrNum extends Array { - 0: string; - 1: number; - length: 2; +interface StrNum extends Array { + 0: string; + 1: number; + length: 2; } var x: [string, number]; -var y: StrNum +var y: StrNum; var z: { - 0: string; - 1: number; - length: 2; -} + 0: string; + 1: number; + length: 2; +}; var [a, b, c] = x; var [d, e, f] = y; @@ -33,3 +33,10 @@ var n3: [number, string] = z; var o1: [string, number] = x; var o2: [string, number] = y; var o3: [string, number] = y; + +// x = y; +// x = z; // 2322 +y = x; +// y = z; // 2740 +// z = x; +// z = y; diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index cc8037bacc..cd711c4fc4 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { - required_error: 3538, - matched_error: 6497, - extra_error: 771, - panic: 74, + required_error: 874, + matched_error: 1749, + extra_error: 284, + panic: 20, } \ No newline at end of file From 3d3fcca67c8326c335e1dd7c0eb29bce1ddc8519 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 3 Jun 2023 22:33:18 +0900 Subject: [PATCH 18/33] fix: replace the order of lhs and rhs --- .../src/analyzer/assign/mod.rs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 68006054b9..06aff9b96f 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1121,24 +1121,24 @@ impl Analyzer<'_, '_> { return Ok(()); } - // (Type::Tuple(Tuple { elems, .. }), Type::Interface(Interface { extends, .. })) => { - // let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); - // for parent in extends { - // let params = parent.type_args.clone().unwrap().params; - // let rhs = self - // .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? - // .freezed(); - // if let Some(Array { elem_type, .. }) = rhs.array() { - // if let Some(Union { types, .. }) = elem_type.union_type() { - // for (lhs, rhs) in lhs.clone().zip(types) { - // if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { - // return self.assign_with_opts(data, lhs, &rhs, opts); - // } - // } - // } - // }; - // } - // } + (Type::Interface(Interface { extends, .. }), Type::Tuple(Tuple { elems, .. })) => { + let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); + for parent in extends { + let params = parent.type_args.clone().unwrap().params; + let rhs = self + .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? + .freezed(); + if let Some(Array { elem_type, .. }) = rhs.array() { + if let Some(Union { types, .. }) = elem_type.union_type() { + for (lhs, rhs) in lhs.clone().zip(types) { + if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { + return self.assign_with_opts(data, lhs, &rhs, opts); + } + } + } + }; + } + } _ => {} } From e4a786b07464ee0b504da0dbb3d5a6db0b6e7c56 Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 3 Jun 2023 23:11:58 +0900 Subject: [PATCH 19/33] feat: correct errors.json --- .../arityAndOrderCompatibility01.errors.json | 111 +++++++++++++++++- ...tyAndOrderCompatibility01.stats.rust-debug | 2 +- .../tuple/arityAndOrderCompatibility01.ts | 10 +- 3 files changed, 116 insertions(+), 7 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json index 78ecf54114..c5c8c9736c 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json @@ -1 +1,110 @@ -[{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":15,"column":12,"code":"TS2493"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":17,"column":5,"code":"TS2461"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":18,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":19,"column":5,"code":"TS2741"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":20,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":21,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":22,"column":5,"code":"TS2741"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":23,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":24,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":25,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":26,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":27,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":28,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":29,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":30,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":31,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":32,"column":5,"code":"TS2322"}] \ No newline at end of file +[ + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 15, + "column": 12, + "code": "TS2493" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 17, + "column": 5, + "code": "TS2461" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 18, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 19, + "column": 5, + "code": "TS2741" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 20, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 21, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 22, + "column": 5, + "code": "TS2741" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 23, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 24, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 25, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 26, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 27, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 28, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 29, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 30, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 31, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 32, + "column": 5, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", + "line": 40, + "column": 5, + "code": "TS2740" + } +] diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug index 600f0901ff..d0d94274fc 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, - matched_error: 17, + matched_error: 18, extra_error: 0, panic: 0, } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts index b577eb0f04..f08b25430c 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts @@ -34,9 +34,9 @@ var o1: [string, number] = x; var o2: [string, number] = y; var o3: [string, number] = y; -// x = y; -// x = z; // 2322 +x = y; +// x = z; // should get TS2322 but pass y = x; -// y = z; // 2740 -// z = x; -// z = y; +y = z; +// z = x; // should pass but got TS2322 +z = y; From fb8d765f2e2da058d1f60795a622518bfa91362d Mon Sep 17 00:00:00 2001 From: henry Date: Sat, 3 Jun 2023 23:54:56 +0900 Subject: [PATCH 20/33] refactor: remove redundant line, reduce clone --- .../stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 06aff9b96f..9a4df62831 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1122,17 +1122,16 @@ impl Analyzer<'_, '_> { } (Type::Interface(Interface { extends, .. }), Type::Tuple(Tuple { elems, .. })) => { - let lhs = elems.iter().map(|TupleElement { ty, .. }| ty); for parent in extends { - let params = parent.type_args.clone().unwrap().params; let rhs = self .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? .freezed(); if let Some(Array { elem_type, .. }) = rhs.array() { - if let Some(Union { types, .. }) = elem_type.union_type() { - for (lhs, rhs) in lhs.clone().zip(types) { - if let (Some(_), Some(_)) = (lhs.to_owned().keyword(), rhs.clone().keyword()) { - return self.assign_with_opts(data, lhs, &rhs, opts); + if let Some(Union { types: rhss, .. }) = elem_type.union_type() { + let lhss = elems.iter().map(|TupleElement { ty, .. }| ty); + for (lhs, rhs) in lhss.zip(rhss.iter()) { + if let (Some(_), Some(_)) = (lhs.clone().keyword(), rhs.clone().keyword()) { + return self.assign_with_opts(data, lhs, rhs, opts); } } } From 0a08ed7c09818e88bfd1ab6e5fa5e22f24e16541 Mon Sep 17 00:00:00 2001 From: henry Date: Sun, 4 Jun 2023 10:53:10 +0900 Subject: [PATCH 21/33] fix: renamt lhss to lsh_types --- crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index 9a4df62831..becd726128 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1127,9 +1127,9 @@ impl Analyzer<'_, '_> { .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? .freezed(); if let Some(Array { elem_type, .. }) = rhs.array() { - if let Some(Union { types: rhss, .. }) = elem_type.union_type() { - let lhss = elems.iter().map(|TupleElement { ty, .. }| ty); - for (lhs, rhs) in lhss.zip(rhss.iter()) { + if let Some(Union { types: rhs_types, .. }) = elem_type.union_type() { + let lhs_types = elems.iter().map(|TupleElement { ty, .. }| ty); + for (lhs, rhs) in lhs_types.zip(rhs_types.iter()) { if let (Some(_), Some(_)) = (lhs.clone().keyword(), rhs.clone().keyword()) { return self.assign_with_opts(data, lhs, rhs, opts); } From bdf5da05d30a90c56a0d2c7740ab112fe186bf7a Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 6 Jun 2023 22:49:10 +0900 Subject: [PATCH 22/33] fix: remove unresolved test cases --- .../conformance/types/tuple/arityAndOrderCompatibility01.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts index f08b25430c..a5a86b1c76 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts @@ -35,8 +35,6 @@ var o2: [string, number] = y; var o3: [string, number] = y; x = y; -// x = z; // should get TS2322 but pass y = x; y = z; -// z = x; // should pass but got TS2322 z = y; From 5759dc274e7918d317597b7df2a7eb19b09bbd44 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 6 Jun 2023 22:49:17 +0900 Subject: [PATCH 23/33] chore: run check.sh --- crates/stc_ts_type_checker/tests/tsc-stats.rust-debug | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index cd711c4fc4..6ad4ce2b90 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { - required_error: 874, + required_error: 888, matched_error: 1749, - extra_error: 284, + extra_error: 289, panic: 20, } \ No newline at end of file From 0da1d654a370a7fbaaf101eee862d2aacc9563a5 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 6 Jun 2023 23:35:14 +0900 Subject: [PATCH 24/33] fix: correct error line number --- .../types/tuple/arityAndOrderCompatibility01.errors.json | 2 +- crates/stc_ts_type_checker/tests/tsc-stats.rust-debug | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json index c5c8c9736c..ebd779a122 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json @@ -103,7 +103,7 @@ }, { "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 40, + "line": 39, "column": 5, "code": "TS2740" } diff --git a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug index 6ad4ce2b90..b96e51fb8c 100644 --- a/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/tsc-stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 888, - matched_error: 1749, - extra_error: 289, + matched_error: 1756, + extra_error: 291, panic: 20, } \ No newline at end of file From 4a839cac66965ffc2593450fa1416b4b9edf5d02 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 29 Dec 2023 13:57:55 +0900 Subject: [PATCH 25/33] fix: recover official tsc conformance test suite --- .../tuple/arityAndOrderCompatibility01.ts | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts index a5a86b1c76..85a035d472 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.ts @@ -1,16 +1,16 @@ -interface StrNum extends Array { - 0: string; - 1: number; - length: 2; +interface StrNum extends Array { + 0: string; + 1: number; + length: 2; } var x: [string, number]; -var y: StrNum; +var y: StrNum var z: { - 0: string; - 1: number; - length: 2; -}; + 0: string; + 1: number; + length: 2; +} var [a, b, c] = x; var [d, e, f] = y; @@ -33,8 +33,3 @@ var n3: [number, string] = z; var o1: [string, number] = x; var o2: [string, number] = y; var o3: [string, number] = y; - -x = y; -y = x; -y = z; -z = y; From 6ba341b7a022c9c6128d911219dc963f507fdd20 Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 29 Dec 2023 14:39:46 +0900 Subject: [PATCH 26/33] fix: remove error on line 39 --- .../types/tuple/arityAndOrderCompatibility01.errors.json | 6 ------ 1 file changed, 6 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json index ebd779a122..094c4f7108 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json @@ -100,11 +100,5 @@ "line": 32, "column": 5, "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 39, - "column": 5, - "code": "TS2740" } ] From 3df5f8b28e7c941788f78a2b791c27efa7e3d24a Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 29 Dec 2023 14:45:39 +0900 Subject: [PATCH 27/33] fix: amend matched_error to 17 --- .../types/tuple/arityAndOrderCompatibility01.stats.rust-debug | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug index d0d94274fc..600f0901ff 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 0, - matched_error: 18, + matched_error: 17, extra_error: 0, panic: 0, } \ No newline at end of file From b8551dbab48770fa29390413ecea034e034c48ae Mon Sep 17 00:00:00 2001 From: henry Date: Fri, 29 Dec 2023 14:56:55 +0900 Subject: [PATCH 28/33] fix: remove formatting --- .../arityAndOrderCompatibility01.errors.json | 105 +----------------- 1 file changed, 1 insertion(+), 104 deletions(-) diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json index 094c4f7108..78ecf54114 100644 --- a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility01.errors.json @@ -1,104 +1 @@ -[ - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 15, - "column": 12, - "code": "TS2493" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 17, - "column": 5, - "code": "TS2461" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 18, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 19, - "column": 5, - "code": "TS2741" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 20, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 21, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 22, - "column": 5, - "code": "TS2741" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 23, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 24, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 25, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 26, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 27, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 28, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 29, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 30, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 31, - "column": 5, - "code": "TS2322" - }, - { - "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts", - "line": 32, - "column": 5, - "code": "TS2322" - } -] +[{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":15,"column":12,"code":"TS2493"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":17,"column":5,"code":"TS2461"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":18,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":19,"column":5,"code":"TS2741"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":20,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":21,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":22,"column":5,"code":"TS2741"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":23,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":24,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":25,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":26,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":27,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":28,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":29,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":30,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":31,"column":5,"code":"TS2322"},{"filename":"tests/cases/conformance/types/tuple/arityAndOrderCompatibility01.ts","line":32,"column":5,"code":"TS2322"}] \ No newline at end of file From 3ea7e93397f923bfb6ebf2bfbd7f20c9db9390f1 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jan 2024 23:24:37 +0900 Subject: [PATCH 29/33] fix: recover solved issue --- .../src/analyzer/assign/mod.rs | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index a09ec3d6e4..f921ceca3b 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -8,7 +8,7 @@ use stc_ts_errors::{ use stc_ts_types::{ Array, Conditional, EnumVariant, Index, IndexedAccessType, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, - TypeLit, TypeParam, Union, + TypeLit, TypeParam, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; @@ -1176,23 +1176,6 @@ impl Analyzer<'_, '_> { return Ok(()); } - (Type::Interface(Interface { extends, .. }), Type::Tuple(Tuple { elems, .. })) => { - for parent in extends { - let rhs = self - .type_of_ts_entity_name(span, &parent.expr, parent.type_args.as_deref())? - .freezed(); - if let Some(Array { elem_type, .. }) = rhs.array() { - if let Some(Union { types: rhs_types, .. }) = elem_type.union_type() { - let lhs_types = elems.iter().map(|TupleElement { ty, .. }| ty); - for (lhs, rhs) in lhs_types.zip(rhs_types.iter()) { - if let (Some(_), Some(_)) = (lhs.clone().keyword(), rhs.clone().keyword()) { - return self.assign_with_opts(data, lhs, rhs, opts); - } - } - } - }; - } - } // function f3(x: T, y: U, k: keyof T) { // x[k] = y[k]; // } From 5f8c1df0ee091d8584cd6faea2496473a31a0bb5 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jan 2024 23:26:43 +0900 Subject: [PATCH 30/33] feat: handle line16 --- .../src/analyzer/assign/mod.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index f921ceca3b..c3d6303764 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -6,9 +6,9 @@ use stc_ts_errors::{ DebugExt, ErrorKind, }; use stc_ts_types::{ - Array, Conditional, EnumVariant, Index, IndexedAccessType, Instance, Interface, Intersection, IntrinsicKind, Key, KeywordType, LitType, - Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, Tuple, TupleElement, Type, TypeElement, - TypeLit, TypeParam, + Array, CommonTypeMetadata, Conditional, EnumVariant, Index, IndexedAccessType, Instance, Interface, Intersection, IntrinsicKind, Key, + KeywordType, KeywordTypeMetadata, LitType, Mapped, PropertySignature, QueryExpr, QueryType, Readonly, Ref, StringMapping, ThisType, + Tuple, TupleElement, Type, TypeElement, TypeLit, TypeParam, }; use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack}; use swc_atoms::js_word; @@ -1156,6 +1156,15 @@ impl Analyzer<'_, '_> { } match (to, rhs) { + ( + Type::Tuple(Tuple { elems, .. }), + Type::TypeLit(TypeLit { + span, + members, + metadata, + tracker, + }), + ) => fail!(), (_, Type::Conditional(rc)) => { let new_true_ty = self.overwrite_conditional(span, rc); @@ -1568,6 +1577,7 @@ impl Analyzer<'_, '_> { } } } + fail!() } }, From 97256d80209bf3e06cf537f12dfaa73ad2cc1a18 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jan 2024 23:27:19 +0900 Subject: [PATCH 31/33] feat: handle line17, 19 --- .../src/analyzer/assign/mod.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs index c3d6303764..1cb8211e16 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs @@ -1578,6 +1578,24 @@ impl Analyzer<'_, '_> { } } + if let RTsLit::Number(_) = &lhs.lit { + if let Type::Keyword(KeywordType { + span, + kind, + metadata: + KeywordTypeMetadata { + common: CommonTypeMetadata { resolved_from_var, .. }, + .. + }, + tracker, + }) = rhs + { + if let (TsKeywordTypeKind::TsNumberKeyword, true) = (kind, resolved_from_var) { + return Ok(()); + } + } + } + fail!() } }, From 66ecbd5db4cccd015a725b9a5b2bfc991b4f798b Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jan 2024 23:28:57 +0900 Subject: [PATCH 32/33] test: add arityAndOrderCompatibility02 case --- .../arityAndOrderCompatibility02.errors.json | 14 +++++++++++++ .../tuple/arityAndOrderCompatibility02.ts | 20 +++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json create mode 100644 crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json new file mode 100644 index 0000000000..65faba821d --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.errors.json @@ -0,0 +1,14 @@ +[ + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility02.ts", + "line": 16, + "column": 0, + "code": "TS2322" + }, + { + "filename": "tests/cases/conformance/types/tuple/arityAndOrderCompatibility02.ts", + "line": 18, + "column": 0, + "code": "TS2740" + } +] diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts new file mode 100644 index 0000000000..1249ffdadf --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.ts @@ -0,0 +1,20 @@ +interface StrNum extends Array { + 0: string; + 1: number; + length: 2; +} + +var x: [string, number]; +var y: StrNum; +var z: { + 0: string; + 1: number; + length: 2; +}; + +x = y; +x = z; // should get ts2322 +y = x; // should pass +y = z; +z = x; // should pass +z = y; From ed10347a4900c6cb9c0f20094f2e230694d5b601 Mon Sep 17 00:00:00 2001 From: henry Date: Thu, 25 Jan 2024 23:29:59 +0900 Subject: [PATCH 33/33] chore: add test log --- .../es2022/es2022IntlAPIs.error-diff.json | 12 ++++++++++++ .../arityAndOrderCompatibility02.stats.rust-debug | 6 ++++++ 2 files changed, 18 insertions(+) create mode 100644 crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json create mode 100644 crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug diff --git a/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json new file mode 100644 index 0000000000..b22aa03fb5 --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/es2022/es2022IntlAPIs.error-diff.json @@ -0,0 +1,12 @@ +{ + "required_errors": {}, + "required_error_lines": {}, + "extra_errors": { + "TS2339": 1 + }, + "extra_error_lines": { + "TS2339": [ + 14 + ] + } +} \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug new file mode 100644 index 0000000000..780225267c --- /dev/null +++ b/crates/stc_ts_type_checker/tests/conformance/types/tuple/arityAndOrderCompatibility02.stats.rust-debug @@ -0,0 +1,6 @@ +Stats { + required_error: 0, + matched_error: 2, + extra_error: 0, + panic: 0, +} \ No newline at end of file