dudykr / stc

Speedy TypeScript type checker
https://stc.dudy.dev
Apache License 2.0
5.77k stars 166 forks source link

Allow more return types for async generators #787

Open kdy1 opened 1 year ago

kdy1 commented 1 year ago

Test case

https://github.com/dudykr/stc/blob/19aab18c6b8e1d71373e3345a0c335f58596bddd/crates/stc_ts_type_checker/tests/conformance/types/asyncGenerators/types.asyncGenerators.es2018.1.ts#L118-L120

We should modify the logic to avoid assigning to the declared return type if a yield expression is in an async generator.

We can do it by checking if it's async iterable before assigning it from

https://github.com/dudykr/stc/blob/19aab18c6b8e1d71373e3345a0c335f58596bddd/crates/stc_ts_file_analyzer/src/analyzer/stmt/return_type.rs#L498-L511

blacktoast commented 1 year ago

Can I try to fix it?

kdy1 commented 1 year ago

Of course, thank you!

kdy1 commented 1 year ago

@blacktoast Are you still willing to work on this?

blacktoast commented 1 year ago

I've been working on it, but I've had a few things happen lately that have prevented me from progressing.

kevinchua6 commented 1 year ago

Hi, I am struggling to run this specific test case. I have tried using ./scripts/test.sh asyncGenerators but it still runs all the test cases. I have also tried running ./scripts/fast.sh but it does not run that specific test case as well. I have tried ./scripts/errors/find-extra.sh TS2504 too but nothing came up on the console. I have also read contributing.md as well.

Please help! ><

sunrabbit123 commented 1 year ago

Hi, I am struggling to run this specific test case. I have tried using ./scripts/test.sh asyncGenerators but it still runs all the test cases. I have also tried running ./scripts/fast.sh but it does not run that specific test case as well. I have tried ./scripts/errors/find-extra.sh TS2504 too but nothing came up on the console. I have also read contributing.md as well.

Please help! ><

can you excute ./scripts/test.sh types.asyncGenerators.es2018.1.ts?

I'll check it out when I get home 10 hours later?

kevinchua6 commented 1 year ago

It works! But it runs all the other 5000 test cases which takes a long time. Is there a way to only run this specific test case?

Output:

     ,-[$DIR/tests/conformance/types/asyncGenerators/types.asyncGenerators.es2018.1.ts:118:1]
 118 | async function * explicitReturnType16(): {} {
 119 |     yield 1;
     :     ^^^^^^^
 120 | }
     `----

============================================================
0 unmatched errors out of 0 errors. Got 4 extra errors.
Wanted: []
Unwanted: [TscError { file: None, line: 31, col: 6, code: 2322 }, TscError { file: None, line: 46, col: 6, code: 2322 }, TscError { file: None, line: 61, col: 6, code: 2322 }, TscError { file: None, line: 119, col: 4, code: 2322 }]

All required errors: []
All actual errors: [TscError { file: None, line: 31, col: 6, code: 2322 }, TscError { file: None, line: 46, col: 6, code: 2322 }, TscError { file: None, line: 61, col: 6, code: 2322 }, TscError { file: None, line: 119, col: 4, code: 2322 }]
thread 'conformance::types::asyncGenerators::types.asyncGenerators.es2018.1.ts' panicked at 'explicit panic', crates/stc_ts_type_checker/tests/tsc.rs:530:9
stack backtrace:
   0: rust_begin_unwind
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/std/src/panicking.rs:578:5
   1: core::panicking::panic_fmt
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/core/src/panicking.rs:67:14
   2: core::panicking::panic
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/core/src/panicking.rs:117:5
   3: tsc::do_test
             at ./tests/tsc.rs:530:9
   4: tsc::create_test::{{closure}}::{{closure}}
             at ./tests/tsc.rs:220:17
   5: std::panicking::try::do_call
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/std/src/panicking.rs:485:40
   6: ___rust_try
   7: std::panicking::try
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/std/src/panicking.rs:449:19
   8: std::panic::catch_unwind
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/std/src/panic.rs:142:14
   9: tsc::create_test::{{closure}}
             at ./tests/tsc.rs:219:23
  10: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/core/src/ops/function.rs:250:5
  11: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/alloc/src/boxed.rs:1985:9
  12: tsc::load_fixtures::{{closure}}
             at ./tests/tsc.rs:730:17
  13: core::ops::function::FnOnce::call_once{{vtable.shim}}
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/core/src/ops/function.rs:250:5
  14: <alloc::boxed::Box<F,A> as core::ops::function::FnOnce<Args>>::call_once
             at /rustc/c373194cb6d882dc455a588bcc29c92a96b50252/library/alloc/src/boxed.rs:1985:9
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

test conformance has been running for over 60 seconds

failures:
    conformance::types::asyncGenerators::types.asyncGenerators.es2018.1.ts

test result: FAILED. 0 passed; 1 failed; 5631 ignored; 0 measured; 0 filtered out; finished in 38.48s

mimalloc: assertion failed: at "./mimalloc/src/segment.c":488, _mi_segment_thread_collect
  assertion: "tld->pages_reset.first == NULL"
error: test failed, to rerun pass `--test tsc`

Caused by:
  process didn't exit successfully: `/Users/kevinchua/Projects/stc/target/debug/deps/tsc-77c925a160f641b6 --quiet` (signal: 6, SIGABRT: process abort signal)
Notifying...

Sure, no problem! No rush haha

sunrabbit123 commented 1 year ago

There is one way to do it

Copy the code and add it to the test case of stc_ts_file_analyzer, then run scripts/fast.sh(docs)