Skip to content
This repository was archived by the owner on Mar 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
370071b
feat: implement interface array case
devgony Jan 14, 2023
ce4cf98
fix: filter array by `type_of_ts_entity_name`
devgony Jan 14, 2023
fc48981
temp-1
devgony Feb 1, 2023
71cefdd
fix: implement handling interface at `assign/mod.rs`
devgony Feb 1, 2023
0399886
Merge branch 'arityAndOrderCompatibility-n' into arityAndOrderCompati…
devgony Feb 1, 2023
96f4567
fix: remove previous implement
devgony Feb 1, 2023
f27ad7e
fix: remove imports
devgony Feb 1, 2023
43f4aec
chore: remove redundant diff
devgony Feb 1, 2023
3194496
Merge remote-tracking branch 'upstream/main' into arityAndOrderCompat…
devgony Feb 1, 2023
20f4513
fix: compare types of lhs and rhs
devgony Feb 6, 2023
bd11c05
fix: zip and iterate each lkind and rkind
devgony Feb 7, 2023
259c374
fix: early return `assign_with_opts`
devgony Feb 7, 2023
5928792
chore: remove unused import
devgony Feb 7, 2023
2e880cb
fix: remove unused params
devgony Feb 7, 2023
135e2b3
fix: remove wrong spell
devgony Feb 7, 2023
e40402d
Merge remote-tracking branch 'upstream/main' into arityAndOrderCompat…
devgony Mar 23, 2023
bba28d3
fix: thanks clippy
devgony Mar 23, 2023
939a9c0
Merge remote-tracking branch 'upstream/main' into arityAndOrderCompat…
devgony May 19, 2023
7e87f8e
style: cargo fmt
devgony May 19, 2023
78011c1
style: thanks clippy
devgony May 19, 2023
b794a61
Merge remote-tracking branch 'upstream/main' into arityAndOrderCompat…
devgony Jun 3, 2023
9d463e3
Merge branch 'main' into arityAndOrderCompatibility
devgony Jun 3, 2023
4976748
test: add a case that should pass
devgony Jun 3, 2023
3d3fcca
fix: replace the order of lhs and rhs
devgony Jun 3, 2023
e85466f
Merge remote-tracking branch 'origin/arityAndOrderCompatibility' into…
devgony Jun 3, 2023
e4a786b
feat: correct errors.json
devgony Jun 3, 2023
fb8d765
refactor: remove redundant line, reduce clone
devgony Jun 3, 2023
0a08ed7
fix: renamt lhss to lsh_types
devgony Jun 4, 2023
bdf5da0
fix: remove unresolved test cases
devgony Jun 6, 2023
5759dc2
chore: run check.sh
devgony Jun 6, 2023
0da1d65
fix: correct error line number
devgony Jun 6, 2023
594c1e1
Merge remote-tracking branch 'upstream/main' into arityAndOrderCompat…
devgony Dec 29, 2023
4a839ca
fix: recover official tsc conformance test suite
devgony Dec 29, 2023
6ba341b
fix: remove error on line 39
devgony Dec 29, 2023
3df5f8b
fix: amend matched_error to 17
devgony Dec 29, 2023
b8551db
fix: remove formatting
devgony Dec 29, 2023
3ea7e93
fix: recover solved issue
devgony Jan 25, 2024
5f8c1df
feat: handle line16
devgony Jan 25, 2024
97256d8
feat: handle line17, 19
devgony Jan 25, 2024
66ecbd5
test: add arityAndOrderCompatibility02 case
devgony Jan 25, 2024
ed10347
chore: add test log
devgony Jan 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion crates/stc_ts_file_analyzer/src/analyzer/assign/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use stc_ts_errors::{
use stc_ts_types::{
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,
TypeParam, Union,
};
use stc_utils::{cache::Freeze, dev_span, ext::SpanExt, stack};
use swc_atoms::js_word;
Expand Down Expand Up @@ -1121,6 +1121,23 @@ 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);
}
}
}
};
}
}
_ => {}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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"}]
[
{
"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"
}
]
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 0,
matched_error: 17,
matched_error: 18,
extra_error: 0,
panic: 0,
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
interface StrNum extends Array<string|number> {
0: string;
1: number;
length: 2;
interface StrNum extends Array<string | number> {
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;
Expand All @@ -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;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please revert this

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This test file is copied from the official tsc conformance test suite, so we should not modify it.

// x = z; // should get TS2322 but pass
y = x;
y = z;
// z = x; // should pass but got TS2322
Copy link
Copy Markdown
Author

@devgony devgony Jun 3, 2023

Choose a reason for hiding this comment

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

According to TS Playground,
It seems that x = z and z = x work in opposite directions.
Should I follow TS playground and fix it in this PR?
image
TSPlayground

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think that this issue is related to the following issue @kdy1
#1005

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

@sunrabbit123
Thanks for the information.
So it looks like it does not need to be fixed, at least in this PR.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

z = x must be not emit 2322
x = z must be emit 2322

I think the code is fine.

And it seems to be out of the conventional test case.

When I commented above, I thought it was an existing test case.
I'm sorry.

z = y;
8 changes: 4 additions & 4 deletions crates/stc_ts_type_checker/tests/tsc-stats.rust-debug
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Stats {
required_error: 3535,
matched_error: 6500,
extra_error: 771,
panic: 74,
required_error: 874,
matched_error: 1749,
extra_error: 284,
panic: 20,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you run check.sh agian?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

I got thread 'conformance::types::uniqueSymbol::uniqueSymbolsDeclarations.ts' has overflowed its stack
Should i pass some option to avoid the overflow?

Copy link
Copy Markdown
Collaborator

@sunrabbit123 sunrabbit123 Jul 10, 2023

Choose a reason for hiding this comment

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

The way is simple

  1. Check that the code you wrote affects stackoverflow.
  2. If it does, insert some stackguards.
  3. if it doesn't, it's broken and you can report it in an issue

Thanks you


The following code detects the overflow and handles it.

let _stack = match stack::track(actual_span) {
                Ok(v) => v,
                Err(err) => {
                    // print_backtrace();
                    return Err(err.into());
                }
            };

}