Skip to content

Move property error spans errors to the name #23865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions src/compiler/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -688,6 +688,8 @@ namespace ts {
case SyntaxKind.GetAccessor:
case SyntaxKind.SetAccessor:
case SyntaxKind.TypeAliasDeclaration:
case SyntaxKind.PropertyDeclaration:
case SyntaxKind.PropertySignature:
errorNode = (<NamedDeclaration>node).name;
break;
case SyntaxKind.ArrowFunction:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts(2,3): error TS1248: A class member cannot have the 'const' keyword.
tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts(2,16): error TS1248: A class member cannot have the 'const' keyword.


==== tests/cases/compiler/ClassDeclarationWithInvalidConstOnPropertyDeclaration.ts (1 errors) ====
class AtomicNumbers {
static const H = 1;
~~~~~~~~~~~~~~~~~~~
~
!!! error TS1248: A class member cannot have the 'const' keyword.
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(37,30): error
==== tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts (6 errors) ====
type T1 = {
x: T1["x"]; // Error
~~~~~~~~~~~
~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
};

type T2<K extends "x" | "y"> = {
x: T2<K>[K]; // Error
~~~~~~~~~~~~
~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
y: number;
}
Expand All @@ -29,13 +29,13 @@ tests/cases/conformance/types/keyof/circularIndexedAccessErrors.ts(37,30): error

interface T4<T extends T4<T>> {
x: T4<T>["x"]; // Error
~~~~~~~~~~~~~~
~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}

class C1 {
x: C1["x"]; // Error
~~~~~~~~~~~
~
!!! error TS2502: 'x' is referenced directly or indirectly in its own type annotation.
}

Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/classIndexer2.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tests/cases/compiler/classIndexer2.ts(4,5): error TS2411: Property 'y' of type '
[s: string]: number;
x: number;
y: string;
~~~~~~~~~~
~
!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'.
constructor() {
}
Expand Down
2 changes: 1 addition & 1 deletion tests/baselines/reference/classIndexer3.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ tests/cases/compiler/classIndexer3.ts(9,5): error TS2411: Property 'y' of type '
class D123 extends C123 {
x: number;
y: string;
~~~~~~~~~~
~
!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'.
}
2 changes: 1 addition & 1 deletion tests/baselines/reference/classIndexer4.errors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ tests/cases/compiler/classIndexer4.ts(9,5): error TS2411: Property 'y' of type '
interface D123 extends C123 {
x: number;
y: string;
~~~~~~~~~~
~
!!! error TS2411: Property 'y' of type 'string' is not assignable to string index type 'number'.
}
55 changes: 55 additions & 0 deletions tests/baselines/reference/classPropertyErrorOnNameOnly.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
tests/cases/compiler/classPropertyErrorOnNameOnly.ts(7,3): error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.
tests/cases/compiler/classPropertyErrorOnNameOnly.ts(24,7): error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
Type 'undefined' is not assignable to type 'string'.


==== tests/cases/compiler/classPropertyErrorOnNameOnly.ts (2 errors) ====
type Values = 1 | 2 | 3 | 4 | 5 | 6

type FuncType = (arg: Values) => string

// turn on strictNullChecks
class Example {
insideClass: FuncType = function(val) { // error span goes from here
~~~~~~~~~~~
!!! error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
!!! error TS2322: Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
} // all the way to here
}

const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case
~~~~~~~~~~~~
!!! error TS2322: Type '(val: Values) => "1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'FuncType'.
!!! error TS2322: Type '"1" | "2" | "3" | "4" | "5" | undefined' is not assignable to type 'string'.
!!! error TS2322: Type 'undefined' is not assignable to type 'string'.
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
}
78 changes: 78 additions & 0 deletions tests/baselines/reference/classPropertyErrorOnNameOnly.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//// [classPropertyErrorOnNameOnly.ts]
type Values = 1 | 2 | 3 | 4 | 5 | 6

type FuncType = (arg: Values) => string

// turn on strictNullChecks
class Example {
insideClass: FuncType = function(val) { // error span goes from here
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
} // all the way to here
}

const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
}

//// [classPropertyErrorOnNameOnly.js]
"use strict";
// turn on strictNullChecks
var Example = /** @class */ (function () {
function Example() {
this.insideClass = function (val) {
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3";
case 4:
return "4";
case 5:
return "5";
// forgot case 6
}
}; // all the way to here
}
return Example;
}());
var outsideClass = function (val) {
switch (val) {
case 1:
return "1";
case 2:
return "2";
case 3:
return "3";
case 4:
return "4";
case 5:
return "5";
// forgot case 6
}
};
57 changes: 57 additions & 0 deletions tests/baselines/reference/classPropertyErrorOnNameOnly.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
=== tests/cases/compiler/classPropertyErrorOnNameOnly.ts ===
type Values = 1 | 2 | 3 | 4 | 5 | 6
>Values : Symbol(Values, Decl(classPropertyErrorOnNameOnly.ts, 0, 0))

type FuncType = (arg: Values) => string
>FuncType : Symbol(FuncType, Decl(classPropertyErrorOnNameOnly.ts, 0, 35))
>arg : Symbol(arg, Decl(classPropertyErrorOnNameOnly.ts, 2, 17))
>Values : Symbol(Values, Decl(classPropertyErrorOnNameOnly.ts, 0, 0))

// turn on strictNullChecks
class Example {
>Example : Symbol(Example, Decl(classPropertyErrorOnNameOnly.ts, 2, 39))

insideClass: FuncType = function(val) { // error span goes from here
>insideClass : Symbol(Example.insideClass, Decl(classPropertyErrorOnNameOnly.ts, 5, 15))
>FuncType : Symbol(FuncType, Decl(classPropertyErrorOnNameOnly.ts, 0, 35))
>val : Symbol(val, Decl(classPropertyErrorOnNameOnly.ts, 6, 35))

switch (val) {
>val : Symbol(val, Decl(classPropertyErrorOnNameOnly.ts, 6, 35))

case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
} // all the way to here
}

const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case
>outsideClass : Symbol(outsideClass, Decl(classPropertyErrorOnNameOnly.ts, 23, 5))
>FuncType : Symbol(FuncType, Decl(classPropertyErrorOnNameOnly.ts, 0, 35))
>val : Symbol(val, Decl(classPropertyErrorOnNameOnly.ts, 23, 40))

switch (val) {
>val : Symbol(val, Decl(classPropertyErrorOnNameOnly.ts, 23, 40))

case 1:
return "1";
case 2:
return "2";
case 3:
return "3"
case 4:
return "4"
case 5:
return "5"
// forgot case 6
}
}
99 changes: 99 additions & 0 deletions tests/baselines/reference/classPropertyErrorOnNameOnly.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=== tests/cases/compiler/classPropertyErrorOnNameOnly.ts ===
type Values = 1 | 2 | 3 | 4 | 5 | 6
>Values : Values

type FuncType = (arg: Values) => string
>FuncType : FuncType
>arg : Values
>Values : Values

// turn on strictNullChecks
class Example {
>Example : Example

insideClass: FuncType = function(val) { // error span goes from here
>insideClass : FuncType
>FuncType : FuncType
>function(val) { // error span goes from here switch (val) { case 1: return "1"; case 2: return "2"; case 3: return "3" case 4: return "4" case 5: return "5" // forgot case 6 } } : (val: Values) => "1" | "2" | "3" | "4" | "5" | undefined
>val : Values

switch (val) {
>val : Values

case 1:
>1 : 1

return "1";
>"1" : "1"

case 2:
>2 : 2

return "2";
>"2" : "2"

case 3:
>3 : 3

return "3"
>"3" : "3"

case 4:
>4 : 4

return "4"
>"4" : "4"

case 5:
>5 : 5

return "5"
>"5" : "5"

// forgot case 6
}
} // all the way to here
}

const outsideClass: FuncType = function(val) { // compare to errors only on this line in this case
>outsideClass : FuncType
>FuncType : FuncType
>function(val) { // compare to errors only on this line in this case switch (val) { case 1: return "1"; case 2: return "2"; case 3: return "3" case 4: return "4" case 5: return "5" // forgot case 6 }} : (val: Values) => "1" | "2" | "3" | "4" | "5" | undefined
>val : Values

switch (val) {
>val : Values

case 1:
>1 : 1

return "1";
>"1" : "1"

case 2:
>2 : 2

return "2";
>"2" : "2"

case 3:
>3 : 3

return "3"
>"3" : "3"

case 4:
>4 : 4

return "4"
>"4" : "4"

case 5:
>5 : 5

return "5"
>"5" : "5"

// forgot case 6
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES5.ts(8,

// Computed properties
[""]: Foo;
~~~~~~~~~~
~~~~
!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ tests/cases/conformance/es6/computedProperties/computedPropertyNames42_ES6.ts(8,

// Computed properties
[""]: Foo;
~~~~~~~~~~
~~~~
!!! error TS2411: Property '[""]' of type 'Foo' is not assignable to string index type 'Foo2'.
}
Loading