From fa1547038db4caa39543843b314c8ebdf1a7b815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=98=A4=EB=B3=91=EC=A7=84?= <64676070+sunrabbit123@users.noreply.github.com> Date: Tue, 14 Nov 2023 22:44:48 +0900 Subject: [PATCH] feat: Remove extra error at `interfaceExtendsObjectIntersectionErrors` (#1103) **Description:** ```ts interface I31 extends T { x: string } ``` I have a concern. The following functions cause duplicate error handling due to duplicate function calls. ```rs #[validator] impl Analyzer<'_, '_> { fn validate(&mut self, d: &RTsInterfaceDecl) -> VResult { let ty = self.with_child(ScopeKind::Flow, Default::default(), |child: &mut Analyzer| -> VResult<_> { match &*d.id.sym { "any" | "void" | "never" | "unknown" | "string" | "number" | "bigint" | "boolean" | "null" | "undefined" | "symbol" => { child.storage.report(ErrorKind::InvalidInterfaceName { span: d.id.span }.into()); } _ => {} } let mut ty = Interface { span: d.span, name: d.id.clone().into(), type_params: try_opt!(d.type_params.validate_with(&mut *child).map(|v| v.map(Box::new))), extends: d.extends.validate_with(child)?.freezed(), body: d.body.validate_with(child)?, metadata: Default::default(), tracker: Default::default(), }; child.prevent_expansion(&mut ty.body); ty.body.freeze(); child.resolve_parent_interfaces(&d.extends, true); child.report_error_for_conflicting_parents(d.id.span, &ty.extends); child.report_error_for_wrong_interface_inheritance(d.id.span, &ty.body, &ty.extends); let ty = Type::Interface(ty).freezed(); Ok(ty) })?; // TODO(kdy1): Recover self.register_type(d.id.clone().into(), ty.clone()); Ok(ty) } } ``` `child.resolve_parent_interfaces` and `child.report_error_for_wrong_interface_inheritance` call `report_error_for_unresolved_type` this fn cause `ErrorKind::TypeNotFound` This PR only clogs the hole. If there seems to be a need for fundamental improvement, please open up the issue --- .../src/analyzer/convert/interface.rs | 5 +++++ .../tsc/types/interface/interfaceDeclaration/1.ts | 3 +++ .../interface/interfaceDeclaration/1.tsc-errors.json | 8 ++++++++ ...faceExtendsObjectIntersectionErrors.error-diff.json | 10 ++-------- ...aceExtendsObjectIntersectionErrors.stats.rust-debug | 2 +- crates/stc_ts_type_checker/tests/tsc-stats.rust-debug | 2 +- 6 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.ts create mode 100644 crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.tsc-errors.json diff --git a/crates/stc_ts_file_analyzer/src/analyzer/convert/interface.rs b/crates/stc_ts_file_analyzer/src/analyzer/convert/interface.rs index ed8e0c9efb..92d623f69f 100644 --- a/crates/stc_ts_file_analyzer/src/analyzer/convert/interface.rs +++ b/crates/stc_ts_file_analyzer/src/analyzer/convert/interface.rs @@ -62,6 +62,11 @@ impl Analyzer<'_, '_> { }; if let Err(err) = res { + if err.code() == 2304 { + // TypeNotFound + return; + } + self.storage.report( ErrorKind::InvalidInterfaceInheritance { span, diff --git a/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.ts b/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.ts new file mode 100644 index 0000000000..f10e0e701d --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.ts @@ -0,0 +1,3 @@ +// @strictNullChecks: true + +interface I31 extends T { x: string } \ No newline at end of file diff --git a/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.tsc-errors.json b/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.tsc-errors.json new file mode 100644 index 0000000000..217c06d3af --- /dev/null +++ b/crates/stc_ts_file_analyzer/tests/tsc/types/interface/interfaceDeclaration/1.tsc-errors.json @@ -0,0 +1,8 @@ +[ + { + "file": "tests/tsc/types/interface/interfaceDeclaration/1.ts", + "line": 3, + "col": 26, + "code": 2312 + } +] \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.error-diff.json b/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.error-diff.json index 05f62357e2..14c1b95d3e 100644 --- a/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.error-diff.json +++ b/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.error-diff.json @@ -32,12 +32,6 @@ 48 ] }, - "extra_errors": { - "TS2430": 1 - }, - "extra_error_lines": { - "TS2430": [ - 49 - ] - } + "extra_errors": {}, + "extra_error_lines": {} } \ No newline at end of file diff --git a/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.stats.rust-debug b/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.stats.rust-debug index ddae7c5fd4..da171bb9dd 100644 --- a/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.stats.rust-debug +++ b/crates/stc_ts_type_checker/tests/conformance/interfaces/interfaceDeclarations/interfaceExtendsObjectIntersectionErrors.stats.rust-debug @@ -1,6 +1,6 @@ Stats { required_error: 14, matched_error: 9, - extra_error: 1, + extra_error: 0, panic: 0, } \ No newline at end of file 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 d972a81e03..61d4808634 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: 2861, matched_error: 7174, - extra_error: 1086, + extra_error: 1085, panic: 3, } \ No newline at end of file