From 68648256f819489b720bded3582df28f0e436785 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Burzy=C5=84ski?= Date: Mon, 29 Jul 2024 13:31:16 -0700 Subject: [PATCH] Fixed crash related to creating file diagnostics outside of the source file range in `checkPotentialUncheckedRenamedBindingElementsInTypes` (#59428) --- src/compiler/checker.ts | 2 +- .../parametersSyntaxErrorNoCrash1.errors.txt | 42 +++++++++++++++++++ .../parametersSyntaxErrorNoCrash2.errors.txt | 35 ++++++++++++++++ .../parametersSyntaxErrorNoCrash3.errors.txt | 37 ++++++++++++++++ .../compiler/parametersSyntaxErrorNoCrash1.ts | 9 ++++ .../compiler/parametersSyntaxErrorNoCrash2.ts | 7 ++++ .../compiler/parametersSyntaxErrorNoCrash3.ts | 9 ++++ 7 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 tests/baselines/reference/parametersSyntaxErrorNoCrash1.errors.txt create mode 100644 tests/baselines/reference/parametersSyntaxErrorNoCrash2.errors.txt create mode 100644 tests/baselines/reference/parametersSyntaxErrorNoCrash3.errors.txt create mode 100644 tests/cases/compiler/parametersSyntaxErrorNoCrash1.ts create mode 100644 tests/cases/compiler/parametersSyntaxErrorNoCrash2.ts create mode 100644 tests/cases/compiler/parametersSyntaxErrorNoCrash3.ts diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 3a540359d81..2578ba4c4df 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -43552,7 +43552,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker { // entire parameter does not have type annotation, suggest adding an annotation addRelatedInfo( diagnostic, - createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 1, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName)), + createFileDiagnostic(getSourceFileOfNode(wrappingDeclaration), wrappingDeclaration.end, 0, Diagnostics.We_can_only_write_a_type_for_0_by_adding_a_type_for_the_entire_parameter_here, declarationNameToString(node.propertyName)), ); } diagnostics.add(diagnostic); diff --git a/tests/baselines/reference/parametersSyntaxErrorNoCrash1.errors.txt b/tests/baselines/reference/parametersSyntaxErrorNoCrash1.errors.txt new file mode 100644 index 00000000000..19991af5050 --- /dev/null +++ b/tests/baselines/reference/parametersSyntaxErrorNoCrash1.errors.txt @@ -0,0 +1,42 @@ +parametersSyntaxErrorNoCrash1.ts(3,10): error TS2391: Function implementation is missing or not immediately following the declaration. +parametersSyntaxErrorNoCrash1.ts(3,10): error TS7010: 'identity', which lacks return-type annotation, implicitly has an 'any' return type. +parametersSyntaxErrorNoCrash1.ts(3,22): error TS2300: Duplicate identifier 'arg'. +parametersSyntaxErrorNoCrash1.ts(3,28): error TS1005: ',' expected. +parametersSyntaxErrorNoCrash1.ts(3,30): error TS7006: Parameter 'T' implicitly has an 'any' type. +parametersSyntaxErrorNoCrash1.ts(3,32): error TS1005: ',' expected. +parametersSyntaxErrorNoCrash1.ts(4,12): error TS1005: ':' expected. +parametersSyntaxErrorNoCrash1.ts(4,12): error TS2300: Duplicate identifier 'arg'. +parametersSyntaxErrorNoCrash1.ts(4,12): error TS2842: 'arg' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +parametersSyntaxErrorNoCrash1.ts(4,15): error TS1005: ',' expected. +parametersSyntaxErrorNoCrash1.ts(5,2): error TS1005: ')' expected. + + +==== parametersSyntaxErrorNoCrash1.ts (11 errors) ==== + // https://github.com/microsoft/TypeScript/issues/59422 + + function identity(arg: T: T { + ~~~~~~~~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + ~~~~~~~~ +!!! error TS7010: 'identity', which lacks return-type annotation, implicitly has an 'any' return type. + ~~~ +!!! error TS2300: Duplicate identifier 'arg'. + ~ +!!! error TS1005: ',' expected. + ~ +!!! error TS7006: Parameter 'T' implicitly has an 'any' type. + ~ +!!! error TS1005: ',' expected. + return arg; + ~~~ +!!! error TS1005: ':' expected. + ~~~ +!!! error TS2300: Duplicate identifier 'arg'. + ~~~ +!!! error TS2842: 'arg' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +!!! related TS2843 parametersSyntaxErrorNoCrash1.ts:5:2: We can only write a type for 'return' by adding a type for the entire parameter here. + ~ +!!! error TS1005: ',' expected. + } + +!!! error TS1005: ')' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parametersSyntaxErrorNoCrash2.errors.txt b/tests/baselines/reference/parametersSyntaxErrorNoCrash2.errors.txt new file mode 100644 index 00000000000..4df2a2a5dda --- /dev/null +++ b/tests/baselines/reference/parametersSyntaxErrorNoCrash2.errors.txt @@ -0,0 +1,35 @@ +parametersSyntaxErrorNoCrash2.ts(3,25): error TS2391: Function implementation is missing or not immediately following the declaration. +parametersSyntaxErrorNoCrash2.ts(3,25): error TS7010: 'getThing', which lacks return-type annotation, implicitly has an 'any' return type. +parametersSyntaxErrorNoCrash2.ts(3,43): error TS2300: Duplicate identifier '(Missing)'. +parametersSyntaxErrorNoCrash2.ts(3,43): error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +parametersSyntaxErrorNoCrash2.ts(3,44): error TS1005: ':' expected. +parametersSyntaxErrorNoCrash2.ts(3,51): error TS2300: Duplicate identifier '(Missing)'. +parametersSyntaxErrorNoCrash2.ts(3,51): error TS2842: '(Missing)' is an unused renaming of ''thing''. Did you intend to use it as a type annotation? +parametersSyntaxErrorNoCrash2.ts(3,51): error TS1005: ':' expected. +parametersSyntaxErrorNoCrash2.ts(3,54): error TS1005: ')' expected. + + +==== parametersSyntaxErrorNoCrash2.ts (9 errors) ==== + // https://github.com/microsoft/TypeScript/issues/59353 + + export default function getThing( { return 'thing'; } + ~~~~~~~~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + ~~~~~~~~ +!!! error TS7010: 'getThing', which lacks return-type annotation, implicitly has an 'any' return type. + +!!! error TS2300: Duplicate identifier '(Missing)'. + +!!! error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +!!! related TS2843 parametersSyntaxErrorNoCrash2.ts:3:54: We can only write a type for 'return' by adding a type for the entire parameter here. + ~~~~~~~ +!!! error TS1005: ':' expected. + +!!! error TS2300: Duplicate identifier '(Missing)'. + +!!! error TS2842: '(Missing)' is an unused renaming of ''thing''. Did you intend to use it as a type annotation? +!!! related TS2843 parametersSyntaxErrorNoCrash2.ts:3:54: We can only write a type for ''thing'' by adding a type for the entire parameter here. + ~ +!!! error TS1005: ':' expected. + +!!! error TS1005: ')' expected. \ No newline at end of file diff --git a/tests/baselines/reference/parametersSyntaxErrorNoCrash3.errors.txt b/tests/baselines/reference/parametersSyntaxErrorNoCrash3.errors.txt new file mode 100644 index 00000000000..7af7ce2b628 --- /dev/null +++ b/tests/baselines/reference/parametersSyntaxErrorNoCrash3.errors.txt @@ -0,0 +1,37 @@ +parametersSyntaxErrorNoCrash3.ts(3,17): error TS2391: Function implementation is missing or not immediately following the declaration. +parametersSyntaxErrorNoCrash3.ts(3,17): error TS7010: 'getHtml', which lacks return-type annotation, implicitly has an 'any' return type. +parametersSyntaxErrorNoCrash3.ts(4,11): error TS2300: Duplicate identifier '(Missing)'. +parametersSyntaxErrorNoCrash3.ts(4,11): error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +parametersSyntaxErrorNoCrash3.ts(4,13): error TS1005: ':' expected. +parametersSyntaxErrorNoCrash3.ts(4,22): error TS2300: Duplicate identifier '(Missing)'. +parametersSyntaxErrorNoCrash3.ts(4,22): error TS2842: '(Missing)' is an unused renaming of '" string"'. Did you intend to use it as a type annotation? +parametersSyntaxErrorNoCrash3.ts(5,1): error TS1005: ':' expected. +parametersSyntaxErrorNoCrash3.ts(5,2): error TS1005: ')' expected. + + +==== parametersSyntaxErrorNoCrash3.ts (9 errors) ==== + // https://github.com/microsoft/TypeScript/issues/59449 + + export function getHtml({ + ~~~~~~~ +!!! error TS2391: Function implementation is missing or not immediately following the declaration. + ~~~~~~~ +!!! error TS7010: 'getHtml', which lacks return-type annotation, implicitly has an 'any' return type. + return " string" // a long string; + +!!! error TS2300: Duplicate identifier '(Missing)'. + +!!! error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation? +!!! related TS2843 parametersSyntaxErrorNoCrash3.ts:5:2: We can only write a type for 'return' by adding a type for the entire parameter here. + ~~~~~~~~~ +!!! error TS1005: ':' expected. + +!!! error TS2300: Duplicate identifier '(Missing)'. + +!!! error TS2842: '(Missing)' is an unused renaming of '" string"'. Did you intend to use it as a type annotation? +!!! related TS2843 parametersSyntaxErrorNoCrash3.ts:5:2: We can only write a type for '" string"' by adding a type for the entire parameter here. + } + ~ +!!! error TS1005: ':' expected. + +!!! error TS1005: ')' expected. \ No newline at end of file diff --git a/tests/cases/compiler/parametersSyntaxErrorNoCrash1.ts b/tests/cases/compiler/parametersSyntaxErrorNoCrash1.ts new file mode 100644 index 00000000000..6c2e86ea475 --- /dev/null +++ b/tests/cases/compiler/parametersSyntaxErrorNoCrash1.ts @@ -0,0 +1,9 @@ +// @strict: true +// @noEmit: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/59422 + +function identity(arg: T: T { + return arg; +} \ No newline at end of file diff --git a/tests/cases/compiler/parametersSyntaxErrorNoCrash2.ts b/tests/cases/compiler/parametersSyntaxErrorNoCrash2.ts new file mode 100644 index 00000000000..353b2f3eaf8 --- /dev/null +++ b/tests/cases/compiler/parametersSyntaxErrorNoCrash2.ts @@ -0,0 +1,7 @@ +// @strict: true +// @noEmit: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/59353 + +export default function getThing( { return 'thing'; } \ No newline at end of file diff --git a/tests/cases/compiler/parametersSyntaxErrorNoCrash3.ts b/tests/cases/compiler/parametersSyntaxErrorNoCrash3.ts new file mode 100644 index 00000000000..5575d753f5d --- /dev/null +++ b/tests/cases/compiler/parametersSyntaxErrorNoCrash3.ts @@ -0,0 +1,9 @@ +// @strict: true +// @noEmit: true +// @noTypesAndSymbols: true + +// https://github.com/microsoft/TypeScript/issues/59449 + +export function getHtml({ + return " string" // a long string; +} \ No newline at end of file