Skip to content

Commit 6864825

Browse files
authored
Fixed crash related to creating file diagnostics outside of the source file range in checkPotentialUncheckedRenamedBindingElementsInTypes (#59428)
1 parent 2daa502 commit 6864825

7 files changed

+140
-1
lines changed

src/compiler/checker.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43552,7 +43552,7 @@ export function createTypeChecker(host: TypeCheckerHost): TypeChecker {
4355243552
// entire parameter does not have type annotation, suggest adding an annotation
4355343553
addRelatedInfo(
4355443554
diagnostic,
43555-
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)),
43555+
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)),
4355643556
);
4355743557
}
4355843558
diagnostics.add(diagnostic);
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
parametersSyntaxErrorNoCrash1.ts(3,10): error TS2391: Function implementation is missing or not immediately following the declaration.
2+
parametersSyntaxErrorNoCrash1.ts(3,10): error TS7010: 'identity', which lacks return-type annotation, implicitly has an 'any' return type.
3+
parametersSyntaxErrorNoCrash1.ts(3,22): error TS2300: Duplicate identifier 'arg'.
4+
parametersSyntaxErrorNoCrash1.ts(3,28): error TS1005: ',' expected.
5+
parametersSyntaxErrorNoCrash1.ts(3,30): error TS7006: Parameter 'T' implicitly has an 'any' type.
6+
parametersSyntaxErrorNoCrash1.ts(3,32): error TS1005: ',' expected.
7+
parametersSyntaxErrorNoCrash1.ts(4,12): error TS1005: ':' expected.
8+
parametersSyntaxErrorNoCrash1.ts(4,12): error TS2300: Duplicate identifier 'arg'.
9+
parametersSyntaxErrorNoCrash1.ts(4,12): error TS2842: 'arg' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
10+
parametersSyntaxErrorNoCrash1.ts(4,15): error TS1005: ',' expected.
11+
parametersSyntaxErrorNoCrash1.ts(5,2): error TS1005: ')' expected.
12+
13+
14+
==== parametersSyntaxErrorNoCrash1.ts (11 errors) ====
15+
// https://github.com/microsoft/TypeScript/issues/59422
16+
17+
function identity<T>(arg: T: T {
18+
~~~~~~~~
19+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
20+
~~~~~~~~
21+
!!! error TS7010: 'identity', which lacks return-type annotation, implicitly has an 'any' return type.
22+
~~~
23+
!!! error TS2300: Duplicate identifier 'arg'.
24+
~
25+
!!! error TS1005: ',' expected.
26+
~
27+
!!! error TS7006: Parameter 'T' implicitly has an 'any' type.
28+
~
29+
!!! error TS1005: ',' expected.
30+
return arg;
31+
~~~
32+
!!! error TS1005: ':' expected.
33+
~~~
34+
!!! error TS2300: Duplicate identifier 'arg'.
35+
~~~
36+
!!! error TS2842: 'arg' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
37+
!!! related TS2843 parametersSyntaxErrorNoCrash1.ts:5:2: We can only write a type for 'return' by adding a type for the entire parameter here.
38+
~
39+
!!! error TS1005: ',' expected.
40+
}
41+
42+
!!! error TS1005: ')' expected.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
parametersSyntaxErrorNoCrash2.ts(3,25): error TS2391: Function implementation is missing or not immediately following the declaration.
2+
parametersSyntaxErrorNoCrash2.ts(3,25): error TS7010: 'getThing', which lacks return-type annotation, implicitly has an 'any' return type.
3+
parametersSyntaxErrorNoCrash2.ts(3,43): error TS2300: Duplicate identifier '(Missing)'.
4+
parametersSyntaxErrorNoCrash2.ts(3,43): error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
5+
parametersSyntaxErrorNoCrash2.ts(3,44): error TS1005: ':' expected.
6+
parametersSyntaxErrorNoCrash2.ts(3,51): error TS2300: Duplicate identifier '(Missing)'.
7+
parametersSyntaxErrorNoCrash2.ts(3,51): error TS2842: '(Missing)' is an unused renaming of ''thing''. Did you intend to use it as a type annotation?
8+
parametersSyntaxErrorNoCrash2.ts(3,51): error TS1005: ':' expected.
9+
parametersSyntaxErrorNoCrash2.ts(3,54): error TS1005: ')' expected.
10+
11+
12+
==== parametersSyntaxErrorNoCrash2.ts (9 errors) ====
13+
// https://github.com/microsoft/TypeScript/issues/59353
14+
15+
export default function getThing( { return 'thing'; }
16+
~~~~~~~~
17+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
18+
~~~~~~~~
19+
!!! error TS7010: 'getThing', which lacks return-type annotation, implicitly has an 'any' return type.
20+
21+
!!! error TS2300: Duplicate identifier '(Missing)'.
22+
23+
!!! error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
24+
!!! related TS2843 parametersSyntaxErrorNoCrash2.ts:3:54: We can only write a type for 'return' by adding a type for the entire parameter here.
25+
~~~~~~~
26+
!!! error TS1005: ':' expected.
27+
28+
!!! error TS2300: Duplicate identifier '(Missing)'.
29+
30+
!!! error TS2842: '(Missing)' is an unused renaming of ''thing''. Did you intend to use it as a type annotation?
31+
!!! related TS2843 parametersSyntaxErrorNoCrash2.ts:3:54: We can only write a type for ''thing'' by adding a type for the entire parameter here.
32+
~
33+
!!! error TS1005: ':' expected.
34+
35+
!!! error TS1005: ')' expected.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
parametersSyntaxErrorNoCrash3.ts(3,17): error TS2391: Function implementation is missing or not immediately following the declaration.
2+
parametersSyntaxErrorNoCrash3.ts(3,17): error TS7010: 'getHtml', which lacks return-type annotation, implicitly has an 'any' return type.
3+
parametersSyntaxErrorNoCrash3.ts(4,11): error TS2300: Duplicate identifier '(Missing)'.
4+
parametersSyntaxErrorNoCrash3.ts(4,11): error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
5+
parametersSyntaxErrorNoCrash3.ts(4,13): error TS1005: ':' expected.
6+
parametersSyntaxErrorNoCrash3.ts(4,22): error TS2300: Duplicate identifier '(Missing)'.
7+
parametersSyntaxErrorNoCrash3.ts(4,22): error TS2842: '(Missing)' is an unused renaming of '" string"'. Did you intend to use it as a type annotation?
8+
parametersSyntaxErrorNoCrash3.ts(5,1): error TS1005: ':' expected.
9+
parametersSyntaxErrorNoCrash3.ts(5,2): error TS1005: ')' expected.
10+
11+
12+
==== parametersSyntaxErrorNoCrash3.ts (9 errors) ====
13+
// https://github.com/microsoft/TypeScript/issues/59449
14+
15+
export function getHtml({
16+
~~~~~~~
17+
!!! error TS2391: Function implementation is missing or not immediately following the declaration.
18+
~~~~~~~
19+
!!! error TS7010: 'getHtml', which lacks return-type annotation, implicitly has an 'any' return type.
20+
return " string" // a long string;
21+
22+
!!! error TS2300: Duplicate identifier '(Missing)'.
23+
24+
!!! error TS2842: '(Missing)' is an unused renaming of 'return'. Did you intend to use it as a type annotation?
25+
!!! related TS2843 parametersSyntaxErrorNoCrash3.ts:5:2: We can only write a type for 'return' by adding a type for the entire parameter here.
26+
~~~~~~~~~
27+
!!! error TS1005: ':' expected.
28+
29+
!!! error TS2300: Duplicate identifier '(Missing)'.
30+
31+
!!! error TS2842: '(Missing)' is an unused renaming of '" string"'. Did you intend to use it as a type annotation?
32+
!!! related TS2843 parametersSyntaxErrorNoCrash3.ts:5:2: We can only write a type for '" string"' by adding a type for the entire parameter here.
33+
}
34+
~
35+
!!! error TS1005: ':' expected.
36+
37+
!!! error TS1005: ')' expected.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @noTypesAndSymbols: true
4+
5+
// https://github.com/microsoft/TypeScript/issues/59422
6+
7+
function identity<T>(arg: T: T {
8+
return arg;
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @noTypesAndSymbols: true
4+
5+
// https://github.com/microsoft/TypeScript/issues/59353
6+
7+
export default function getThing( { return 'thing'; }
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// @strict: true
2+
// @noEmit: true
3+
// @noTypesAndSymbols: true
4+
5+
// https://github.com/microsoft/TypeScript/issues/59449
6+
7+
export function getHtml({
8+
return " string" // a long string;
9+
}

0 commit comments

Comments
 (0)