Issue an error when a derived class precedes its base class

This commit is contained in:
Ryan Cavanaugh
2016-05-16 22:08:56 -07:00
parent 5433553131
commit b693180ab7
40 changed files with 1380 additions and 27771 deletions
+6
View File
@@ -15179,6 +15179,12 @@ namespace ts {
checkTypeAssignableTo(staticType, getTypeWithoutSignatures(staticBaseType), node.name || node,
Diagnostics.Class_static_side_0_incorrectly_extends_base_class_static_side_1);
if (baseType.symbol.valueDeclaration && !(baseType.symbol.valueDeclaration.flags & NodeFlags.Ambient)) {
if (!isBlockScopedNameDeclaredBeforeUse(baseType.symbol.valueDeclaration, node)) {
error(baseTypeNode, Diagnostics.A_class_must_be_declared_after_its_base_class);
}
}
if (!(staticBaseType.symbol && staticBaseType.symbol.flags & SymbolFlags.Class)) {
// When the static base type is a "class-like" constructor function (but not actually a class), we verify
// that all instantiated base constructor signatures return the same type. We can simply compare the type
+4
View File
@@ -1923,6 +1923,10 @@
"category": "Error",
"code": 2685
},
"A class must be declared after its base class.": {
"category": "Error",
"code": 2686
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
@@ -0,0 +1,35 @@
tests/cases/compiler/baseTypeWrappingInstantiationChain.ts(1,21): error TS2686: A class must be declared after its base class.
tests/cases/compiler/baseTypeWrappingInstantiationChain.ts(12,25): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts (2 errors) ====
class C<T1> extends CBase<T1> {
~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
public works() {
new CBaseBase<Wrapper<T1>>(this);
}
public alsoWorks() {
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
}
public method(t: Wrapper<T1>) { }
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
}
class CBaseBase<T3> {
constructor(x: Parameter<T3>) { }
}
class Parameter<T4> {
method(t: T4) { }
}
class Wrapper<T5> {
property: T5;
}
@@ -1,69 +0,0 @@
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
class C<T1> extends CBase<T1> {
>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
public works() {
>works : Symbol(C.works, Decl(baseTypeWrappingInstantiationChain.ts, 0, 31))
new CBaseBase<Wrapper<T1>>(this);
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
}
public alsoWorks() {
>alsoWorks : Symbol(C.alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 3, 5))
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
}
public method(t: Wrapper<T1>) { }
>method : Symbol(C.method, Decl(baseTypeWrappingInstantiationChain.ts, 6, 5))
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 8, 18))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 0, 8))
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 9, 1))
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 11, 12))
}
class CBaseBase<T3> {
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 13, 1))
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
constructor(x: Parameter<T3>) { }
>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 16, 16))
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 15, 16))
}
class Parameter<T4> {
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 17, 1))
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
method(t: T4) { }
>method : Symbol(Parameter.method, Decl(baseTypeWrappingInstantiationChain.ts, 19, 21))
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 20, 11))
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 19, 16))
}
class Wrapper<T5> {
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
property: T5;
>property : Symbol(Wrapper.property, Decl(baseTypeWrappingInstantiationChain.ts, 23, 19))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
}
@@ -1,71 +0,0 @@
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
class C<T1> extends CBase<T1> {
>C : C<T1>
>T1 : T1
>CBase : CBase<T1>
>T1 : T1
public works() {
>works : () => void
new CBaseBase<Wrapper<T1>>(this);
>new CBaseBase<Wrapper<T1>>(this) : CBaseBase<Wrapper<T1>>
>CBaseBase : typeof CBaseBase
>Wrapper : Wrapper<T5>
>T1 : T1
>this : this
}
public alsoWorks() {
>alsoWorks : () => void
new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
>new CBase<T1>(this) : CBase<T1>
>CBase : typeof CBase
>T1 : T1
>this : this
}
public method(t: Wrapper<T1>) { }
>method : (t: Wrapper<T1>) => void
>t : Wrapper<T1>
>Wrapper : Wrapper<T5>
>T1 : T1
}
class CBase<T2> extends CBaseBase<Wrapper<T2>> {
>CBase : CBase<T2>
>T2 : T2
>CBaseBase : CBaseBase<Wrapper<T2>>
>Wrapper : Wrapper<T5>
>T2 : T2
}
class CBaseBase<T3> {
>CBaseBase : CBaseBase<T3>
>T3 : T3
constructor(x: Parameter<T3>) { }
>x : Parameter<T3>
>Parameter : Parameter<T4>
>T3 : T3
}
class Parameter<T4> {
>Parameter : Parameter<T4>
>T4 : T4
method(t: T4) { }
>method : (t: T4) => void
>t : T4
>T4 : T4
}
class Wrapper<T5> {
>Wrapper : Wrapper<T5>
>T5 : T5
property: T5;
>property : T5
>T5 : T5
}
@@ -0,0 +1,25 @@
tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts(5,28): error TS2686: A class must be declared after its base class.
==== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts (1 errors) ====
// expected no error
module B {
export import a = A;
export class D extends a.C {
~~~
!!! error TS2686: A class must be declared after its base class.
id: number;
}
}
module A {
export class C { name: string }
export import b = B;
}
var c: { name: string };
var c = new B.a.C();
@@ -1,47 +0,0 @@
=== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts ===
// expected no error
module B {
>B : Symbol(a.b, Decl(circularImportAlias.ts, 0, 0))
export import a = A;
>a : Symbol(a, Decl(circularImportAlias.ts, 2, 10))
>A : Symbol(a, Decl(circularImportAlias.ts, 7, 1))
export class D extends a.C {
>D : Symbol(D, Decl(circularImportAlias.ts, 3, 24))
>a.C : Symbol(a.C, Decl(circularImportAlias.ts, 9, 10))
>a : Symbol(a, Decl(circularImportAlias.ts, 2, 10))
>C : Symbol(a.C, Decl(circularImportAlias.ts, 9, 10))
id: number;
>id : Symbol(D.id, Decl(circularImportAlias.ts, 4, 32))
}
}
module A {
>A : Symbol(b.a, Decl(circularImportAlias.ts, 7, 1))
export class C { name: string }
>C : Symbol(C, Decl(circularImportAlias.ts, 9, 10))
>name : Symbol(C.name, Decl(circularImportAlias.ts, 10, 20))
export import b = B;
>b : Symbol(b, Decl(circularImportAlias.ts, 10, 35))
>B : Symbol(b, Decl(circularImportAlias.ts, 0, 0))
}
var c: { name: string };
>c : Symbol(c, Decl(circularImportAlias.ts, 14, 3), Decl(circularImportAlias.ts, 15, 3))
>name : Symbol(name, Decl(circularImportAlias.ts, 14, 8))
var c = new B.a.C();
>c : Symbol(c, Decl(circularImportAlias.ts, 14, 3), Decl(circularImportAlias.ts, 15, 3))
>B.a.C : Symbol(A.C, Decl(circularImportAlias.ts, 9, 10))
>B.a : Symbol(B.a, Decl(circularImportAlias.ts, 2, 10))
>B : Symbol(B, Decl(circularImportAlias.ts, 0, 0))
>a : Symbol(B.a, Decl(circularImportAlias.ts, 2, 10))
>C : Symbol(A.C, Decl(circularImportAlias.ts, 9, 10))
@@ -1,48 +0,0 @@
=== tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts ===
// expected no error
module B {
>B : typeof a.b
export import a = A;
>a : typeof a
>A : typeof a
export class D extends a.C {
>D : D
>a.C : a.C
>a : typeof a
>C : typeof a.C
id: number;
>id : number
}
}
module A {
>A : typeof b.a
export class C { name: string }
>C : C
>name : string
export import b = B;
>b : typeof b
>B : typeof b
}
var c: { name: string };
>c : { name: string; }
>name : string
var c = new B.a.C();
>c : { name: string; }
>new B.a.C() : A.C
>B.a.C : typeof A.C
>B.a : typeof A
>B : typeof B
>a : typeof A
>C : typeof A.C
@@ -0,0 +1,15 @@
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,23): error TS2686: A class must be declared after its base class.
tests/cases/conformance/classes/classExpressions/classExpression3.ts(1,37): error TS2686: A class must be declared after its base class.
==== tests/cases/conformance/classes/classExpressions/classExpression3.ts (2 errors) ====
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
let c = new C();
c.a;
c.b;
c.c;
@@ -1,26 +0,0 @@
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
let c = new C();
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
>C : Symbol(C, Decl(classExpression3.ts, 0, 3))
c.a;
>c.a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
>a : Symbol((Anonymous class).a, Decl(classExpression3.ts, 0, 43))
c.b;
>c.b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
>b : Symbol((Anonymous class).b, Decl(classExpression3.ts, 0, 53))
c.c;
>c.c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
>c : Symbol(c, Decl(classExpression3.ts, 1, 3))
>c : Symbol((Anonymous class).c, Decl(classExpression3.ts, 0, 63))
@@ -1,33 +0,0 @@
=== tests/cases/conformance/classes/classExpressions/classExpression3.ts ===
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
>C : typeof (Anonymous class)
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
>class { a = 1 } : (Anonymous class)
>a : number
>1 : number
>b : number
>2 : number
>c : number
>3 : number
let c = new C();
>c : (Anonymous class)
>new C() : (Anonymous class)
>C : typeof (Anonymous class)
c.a;
>c.a : number
>c : (Anonymous class)
>a : number
c.b;
>c.b : number
>c : (Anonymous class)
>b : number
c.c;
>c.c : number
>c : (Anonymous class)
>c : number
@@ -0,0 +1,15 @@
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,23): error TS2686: A class must be declared after its base class.
tests/cases/conformance/es6/classExpressions/classExpressionES63.ts(1,37): error TS2686: A class must be declared after its base class.
==== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts (2 errors) ====
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
let c = new C();
c.a;
c.b;
c.c;
@@ -1,26 +0,0 @@
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
let c = new C();
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
>C : Symbol(C, Decl(classExpressionES63.ts, 0, 3))
c.a;
>c.a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
>a : Symbol((Anonymous class).a, Decl(classExpressionES63.ts, 0, 43))
c.b;
>c.b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
>b : Symbol((Anonymous class).b, Decl(classExpressionES63.ts, 0, 53))
c.c;
>c.c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
>c : Symbol(c, Decl(classExpressionES63.ts, 1, 3))
>c : Symbol((Anonymous class).c, Decl(classExpressionES63.ts, 0, 63))
@@ -1,33 +0,0 @@
=== tests/cases/conformance/es6/classExpressions/classExpressionES63.ts ===
let C = class extends class extends class { a = 1 } { b = 2 } { c = 3 };
>C : typeof (Anonymous class)
>class extends class extends class { a = 1 } { b = 2 } { c = 3 } : typeof (Anonymous class)
>class extends class { a = 1 } { b = 2 } : (Anonymous class)
>class { a = 1 } : (Anonymous class)
>a : number
>1 : number
>b : number
>2 : number
>c : number
>3 : number
let c = new C();
>c : (Anonymous class)
>new C() : (Anonymous class)
>C : typeof (Anonymous class)
c.a;
>c.a : number
>c : (Anonymous class)
>a : number
c.b;
>c.b : number
>c : (Anonymous class)
>b : number
c.c;
>c.c : number
>c : (Anonymous class)
>c : number
@@ -1,8 +1,11 @@
tests/cases/compiler/classInheritence.ts(1,17): error TS2686: A class must be declared after its base class.
tests/cases/compiler/classInheritence.ts(2,7): error TS2506: 'A' is referenced directly or indirectly in its own base expression.
==== tests/cases/compiler/classInheritence.ts (1 errors) ====
==== tests/cases/compiler/classInheritence.ts (2 errors) ====
class B extends A { }
~
!!! error TS2686: A class must be declared after its base class.
class A extends A { }
~
!!! error TS2506: 'A' is referenced directly or indirectly in its own base expression.
@@ -0,0 +1,25 @@
tests/cases/compiler/classOrder2.ts(2,17): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/classOrder2.ts (1 errors) ====
class A extends B {
~
!!! error TS2686: A class must be declared after its base class.
foo() { this.bar(); }
}
class B {
bar() { }
}
var a = new A();
a.foo();
@@ -1,33 +0,0 @@
=== tests/cases/compiler/classOrder2.ts ===
class A extends B {
>A : Symbol(A, Decl(classOrder2.ts, 0, 0))
>B : Symbol(B, Decl(classOrder2.ts, 5, 1))
foo() { this.bar(); }
>foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
>this.bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
>this : Symbol(A, Decl(classOrder2.ts, 0, 0))
>bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
}
class B {
>B : Symbol(B, Decl(classOrder2.ts, 5, 1))
bar() { }
>bar : Symbol(B.bar, Decl(classOrder2.ts, 7, 9))
}
var a = new A();
>a : Symbol(a, Decl(classOrder2.ts, 14, 3))
>A : Symbol(A, Decl(classOrder2.ts, 0, 0))
a.foo();
>a.foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
>a : Symbol(a, Decl(classOrder2.ts, 14, 3))
>foo : Symbol(A.foo, Decl(classOrder2.ts, 1, 19))
@@ -1,36 +0,0 @@
=== tests/cases/compiler/classOrder2.ts ===
class A extends B {
>A : A
>B : B
foo() { this.bar(); }
>foo : () => void
>this.bar() : void
>this.bar : () => void
>this : this
>bar : () => void
}
class B {
>B : B
bar() { }
>bar : () => void
}
var a = new A();
>a : A
>new A() : A
>A : typeof A
a.foo();
>a.foo() : void
>a.foo : () => void
>a : A
>foo : () => void
@@ -0,0 +1,26 @@
tests/cases/compiler/classSideInheritance2.ts(7,23): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/classSideInheritance2.ts (1 errors) ====
interface IText {
foo: number;
}
interface TextSpan {}
class SubText extends TextBase {
~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
constructor(text: IText, span: TextSpan) {
super();
}
}
class TextBase implements IText {
public foo: number;
public subText(span: TextSpan): IText {
return new SubText(this, span);
}
}
@@ -1,45 +0,0 @@
=== tests/cases/compiler/classSideInheritance2.ts ===
interface IText {
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
foo: number;
>foo : Symbol(IText.foo, Decl(classSideInheritance2.ts, 0, 17))
}
interface TextSpan {}
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
class SubText extends TextBase {
>SubText : Symbol(SubText, Decl(classSideInheritance2.ts, 4, 21))
>TextBase : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
constructor(text: IText, span: TextSpan) {
>text : Symbol(text, Decl(classSideInheritance2.ts, 8, 20))
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
>span : Symbol(span, Decl(classSideInheritance2.ts, 8, 32))
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
super();
>super : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
}
}
class TextBase implements IText {
>TextBase : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
public foo: number;
>foo : Symbol(TextBase.foo, Decl(classSideInheritance2.ts, 13, 33))
public subText(span: TextSpan): IText {
>subText : Symbol(TextBase.subText, Decl(classSideInheritance2.ts, 14, 27))
>span : Symbol(span, Decl(classSideInheritance2.ts, 15, 23))
>TextSpan : Symbol(TextSpan, Decl(classSideInheritance2.ts, 2, 1))
>IText : Symbol(IText, Decl(classSideInheritance2.ts, 0, 0))
return new SubText(this, span);
>SubText : Symbol(SubText, Decl(classSideInheritance2.ts, 4, 21))
>this : Symbol(TextBase, Decl(classSideInheritance2.ts, 11, 1))
>span : Symbol(span, Decl(classSideInheritance2.ts, 15, 23))
}
}
@@ -1,47 +0,0 @@
=== tests/cases/compiler/classSideInheritance2.ts ===
interface IText {
>IText : IText
foo: number;
>foo : number
}
interface TextSpan {}
>TextSpan : TextSpan
class SubText extends TextBase {
>SubText : SubText
>TextBase : TextBase
constructor(text: IText, span: TextSpan) {
>text : IText
>IText : IText
>span : TextSpan
>TextSpan : TextSpan
super();
>super() : void
>super : typeof TextBase
}
}
class TextBase implements IText {
>TextBase : TextBase
>IText : IText
public foo: number;
>foo : number
public subText(span: TextSpan): IText {
>subText : (span: TextSpan) => IText
>span : TextSpan
>TextSpan : TextSpan
>IText : IText
return new SubText(this, span);
>new SubText(this, span) : SubText
>SubText : typeof SubText
>this : this
>span : TextSpan
}
}
@@ -0,0 +1,53 @@
tests/cases/compiler/complexClassRelationships.ts(2,23): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/complexClassRelationships.ts (1 errors) ====
// There should be no errors in this file
class Derived extends Base {
~~~~
!!! error TS2686: A class must be declared after its base class.
public static createEmpty(): Derived {
var item = new Derived();
return item;
}
}
class BaseCollection<T extends Base> {
constructor(f: () => T) {
(item: Thing) => { return [item.Components]; };
}
}
class Base {
ownerCollection: BaseCollection<Base>;
}
class Thing {
public get Components(): ComponentCollection<any> { return null }
}
class ComponentCollection<T> {
private static sortComponents(p: Foo) {
return p.prop1;
}
}
class Foo {
public get prop1() {
return new GenericType<string>(this);
}
public populate() {
this.prop2;
}
public get prop2(): BaseCollection<Derived> {
return new BaseCollection<Derived>(Derived.createEmpty);
}
}
class GenericType<T> {
constructor(parent: FooBase) { }
}
class FooBase {
public populate() {
}
}
@@ -1,117 +0,0 @@
=== tests/cases/compiler/complexClassRelationships.ts ===
// There should be no errors in this file
class Derived extends Base {
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
public static createEmpty(): Derived {
>createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
var item = new Derived();
>item : Symbol(item, Decl(complexClassRelationships.ts, 3, 11))
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
return item;
>item : Symbol(item, Decl(complexClassRelationships.ts, 3, 11))
}
}
class BaseCollection<T extends Base> {
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
>T : Symbol(T, Decl(complexClassRelationships.ts, 7, 21))
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
constructor(f: () => T) {
>f : Symbol(f, Decl(complexClassRelationships.ts, 8, 16))
>T : Symbol(T, Decl(complexClassRelationships.ts, 7, 21))
(item: Thing) => { return [item.Components]; };
>item : Symbol(item, Decl(complexClassRelationships.ts, 9, 9))
>Thing : Symbol(Thing, Decl(complexClassRelationships.ts, 14, 1))
>item.Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
>item : Symbol(item, Decl(complexClassRelationships.ts, 9, 9))
>Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
}
}
class Base {
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
ownerCollection: BaseCollection<Base>;
>ownerCollection : Symbol(Base.ownerCollection, Decl(complexClassRelationships.ts, 12, 12))
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
>Base : Symbol(Base, Decl(complexClassRelationships.ts, 11, 1))
}
class Thing {
>Thing : Symbol(Thing, Decl(complexClassRelationships.ts, 14, 1))
public get Components(): ComponentCollection<any> { return null }
>Components : Symbol(Thing.Components, Decl(complexClassRelationships.ts, 16, 13))
>ComponentCollection : Symbol(ComponentCollection, Decl(complexClassRelationships.ts, 18, 1))
}
class ComponentCollection<T> {
>ComponentCollection : Symbol(ComponentCollection, Decl(complexClassRelationships.ts, 18, 1))
>T : Symbol(T, Decl(complexClassRelationships.ts, 20, 26))
private static sortComponents(p: Foo) {
>sortComponents : Symbol(ComponentCollection.sortComponents, Decl(complexClassRelationships.ts, 20, 30))
>p : Symbol(p, Decl(complexClassRelationships.ts, 21, 34))
>Foo : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
return p.prop1;
>p.prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
>p : Symbol(p, Decl(complexClassRelationships.ts, 21, 34))
>prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
}
}
class Foo {
>Foo : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
public get prop1() {
>prop1 : Symbol(Foo.prop1, Decl(complexClassRelationships.ts, 26, 11))
return new GenericType<string>(this);
>GenericType : Symbol(GenericType, Decl(complexClassRelationships.ts, 36, 1))
>this : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
}
public populate() {
>populate : Symbol(Foo.populate, Decl(complexClassRelationships.ts, 29, 5))
this.prop2;
>this.prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
>this : Symbol(Foo, Decl(complexClassRelationships.ts, 24, 1))
>prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
}
public get prop2(): BaseCollection<Derived> {
>prop2 : Symbol(Foo.prop2, Decl(complexClassRelationships.ts, 32, 5))
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
return new BaseCollection<Derived>(Derived.createEmpty);
>BaseCollection : Symbol(BaseCollection, Decl(complexClassRelationships.ts, 6, 1))
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
>Derived.createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
>Derived : Symbol(Derived, Decl(complexClassRelationships.ts, 0, 0))
>createEmpty : Symbol(Derived.createEmpty, Decl(complexClassRelationships.ts, 1, 28))
}
}
class GenericType<T> {
>GenericType : Symbol(GenericType, Decl(complexClassRelationships.ts, 36, 1))
>T : Symbol(T, Decl(complexClassRelationships.ts, 38, 18))
constructor(parent: FooBase) { }
>parent : Symbol(parent, Decl(complexClassRelationships.ts, 39, 16))
>FooBase : Symbol(FooBase, Decl(complexClassRelationships.ts, 40, 1))
}
class FooBase {
>FooBase : Symbol(FooBase, Decl(complexClassRelationships.ts, 40, 1))
public populate() {
>populate : Symbol(FooBase.populate, Decl(complexClassRelationships.ts, 42, 15))
}
}
@@ -1,123 +0,0 @@
=== tests/cases/compiler/complexClassRelationships.ts ===
// There should be no errors in this file
class Derived extends Base {
>Derived : Derived
>Base : Base
public static createEmpty(): Derived {
>createEmpty : () => Derived
>Derived : Derived
var item = new Derived();
>item : Derived
>new Derived() : Derived
>Derived : typeof Derived
return item;
>item : Derived
}
}
class BaseCollection<T extends Base> {
>BaseCollection : BaseCollection<T>
>T : T
>Base : Base
constructor(f: () => T) {
>f : () => T
>T : T
(item: Thing) => { return [item.Components]; };
>(item: Thing) => { return [item.Components]; } : (item: Thing) => ComponentCollection<any>[]
>item : Thing
>Thing : Thing
>[item.Components] : ComponentCollection<any>[]
>item.Components : ComponentCollection<any>
>item : Thing
>Components : ComponentCollection<any>
}
}
class Base {
>Base : Base
ownerCollection: BaseCollection<Base>;
>ownerCollection : BaseCollection<Base>
>BaseCollection : BaseCollection<T>
>Base : Base
}
class Thing {
>Thing : Thing
public get Components(): ComponentCollection<any> { return null }
>Components : ComponentCollection<any>
>ComponentCollection : ComponentCollection<T>
>null : null
}
class ComponentCollection<T> {
>ComponentCollection : ComponentCollection<T>
>T : T
private static sortComponents(p: Foo) {
>sortComponents : (p: Foo) => GenericType<string>
>p : Foo
>Foo : Foo
return p.prop1;
>p.prop1 : GenericType<string>
>p : Foo
>prop1 : GenericType<string>
}
}
class Foo {
>Foo : Foo
public get prop1() {
>prop1 : GenericType<string>
return new GenericType<string>(this);
>new GenericType<string>(this) : GenericType<string>
>GenericType : typeof GenericType
>this : this
}
public populate() {
>populate : () => void
this.prop2;
>this.prop2 : BaseCollection<Derived>
>this : this
>prop2 : BaseCollection<Derived>
}
public get prop2(): BaseCollection<Derived> {
>prop2 : BaseCollection<Derived>
>BaseCollection : BaseCollection<T>
>Derived : Derived
return new BaseCollection<Derived>(Derived.createEmpty);
>new BaseCollection<Derived>(Derived.createEmpty) : BaseCollection<Derived>
>BaseCollection : typeof BaseCollection
>Derived : Derived
>Derived.createEmpty : () => Derived
>Derived : typeof Derived
>createEmpty : () => Derived
}
}
class GenericType<T> {
>GenericType : GenericType<T>
>T : T
constructor(parent: FooBase) { }
>parent : FooBase
>FooBase : FooBase
}
class FooBase {
>FooBase : FooBase
public populate() {
>populate : () => void
}
}
@@ -0,0 +1,36 @@
tests/cases/compiler/derivedClasses.ts(1,19): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/derivedClasses.ts (1 errors) ====
class Red extends Color {
~~~~~
!!! error TS2686: A class must be declared after its base class.
public shade() {
var getHue = () => { return this.hue(); };
return getHue() + " red";
}
}
class Color {
public shade() { return "some shade"; }
public hue() { return "some hue"; }
}
class Blue extends Color {
public shade() {
var getHue = () => { return this.hue(); };
return getHue() + " blue";
}
}
var r = new Red();
var b = new Blue();
r.shade();
r.hue();
b.shade();
b.hue();
@@ -1,77 +0,0 @@
=== tests/cases/compiler/derivedClasses.ts ===
class Red extends Color {
>Red : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
public shade() {
>shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
var getHue = () => { return this.hue(); };
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 2, 8))
>this.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
>this : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
return getHue() + " red";
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 2, 8))
}
}
class Color {
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
public shade() { return "some shade"; }
>shade : Symbol(Color.shade, Decl(derivedClasses.ts, 7, 13))
public hue() { return "some hue"; }
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
}
class Blue extends Color {
>Blue : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
>Color : Symbol(Color, Decl(derivedClasses.ts, 5, 1))
public shade() {
>shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
var getHue = () => { return this.hue(); };
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 15, 8))
>this.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
>this : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
return getHue() + " blue";
>getHue : Symbol(getHue, Decl(derivedClasses.ts, 15, 8))
}
}
var r = new Red();
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
>Red : Symbol(Red, Decl(derivedClasses.ts, 0, 0))
var b = new Blue();
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
>Blue : Symbol(Blue, Decl(derivedClasses.ts, 10, 1))
r.shade();
>r.shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
>shade : Symbol(Red.shade, Decl(derivedClasses.ts, 0, 25))
r.hue();
>r.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
>r : Symbol(r, Decl(derivedClasses.ts, 20, 3))
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
b.shade();
>b.shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
>shade : Symbol(Blue.shade, Decl(derivedClasses.ts, 12, 26))
b.hue();
>b.hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
>b : Symbol(b, Decl(derivedClasses.ts, 21, 3))
>hue : Symbol(Color.hue, Decl(derivedClasses.ts, 8, 43))
@@ -1,95 +0,0 @@
=== tests/cases/compiler/derivedClasses.ts ===
class Red extends Color {
>Red : Red
>Color : Color
public shade() {
>shade : () => string
var getHue = () => { return this.hue(); };
>getHue : () => string
>() => { return this.hue(); } : () => string
>this.hue() : string
>this.hue : () => string
>this : this
>hue : () => string
return getHue() + " red";
>getHue() + " red" : string
>getHue() : string
>getHue : () => string
>" red" : string
}
}
class Color {
>Color : Color
public shade() { return "some shade"; }
>shade : () => string
>"some shade" : string
public hue() { return "some hue"; }
>hue : () => string
>"some hue" : string
}
class Blue extends Color {
>Blue : Blue
>Color : Color
public shade() {
>shade : () => string
var getHue = () => { return this.hue(); };
>getHue : () => string
>() => { return this.hue(); } : () => string
>this.hue() : string
>this.hue : () => string
>this : this
>hue : () => string
return getHue() + " blue";
>getHue() + " blue" : string
>getHue() : string
>getHue : () => string
>" blue" : string
}
}
var r = new Red();
>r : Red
>new Red() : Red
>Red : typeof Red
var b = new Blue();
>b : Blue
>new Blue() : Blue
>Blue : typeof Blue
r.shade();
>r.shade() : string
>r.shade : () => string
>r : Red
>shade : () => string
r.hue();
>r.hue() : string
>r.hue : () => string
>r : Red
>hue : () => string
b.shade();
>b.shade() : string
>b.shade : () => string
>b : Blue
>shade : () => string
b.hue();
>b.hue() : string
>b.hue : () => string
>b : Blue
>hue : () => string
@@ -0,0 +1,9 @@
tests/cases/compiler/extendBaseClassBeforeItsDeclared.ts(1,23): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/extendBaseClassBeforeItsDeclared.ts (1 errors) ====
class derived extends base { }
~~~~
!!! error TS2686: A class must be declared after its base class.
class base { constructor (public n: number) { } }
@@ -1,9 +0,0 @@
=== tests/cases/compiler/extendBaseClassBeforeItsDeclared.ts ===
class derived extends base { }
>derived : Symbol(derived, Decl(extendBaseClassBeforeItsDeclared.ts, 0, 0))
>base : Symbol(base, Decl(extendBaseClassBeforeItsDeclared.ts, 0, 30))
class base { constructor (public n: number) { } }
>base : Symbol(base, Decl(extendBaseClassBeforeItsDeclared.ts, 0, 30))
>n : Symbol(base.n, Decl(extendBaseClassBeforeItsDeclared.ts, 2, 26))
@@ -1,9 +0,0 @@
=== tests/cases/compiler/extendBaseClassBeforeItsDeclared.ts ===
class derived extends base { }
>derived : derived
>base : base
class base { constructor (public n: number) { } }
>base : base
>n : number
@@ -0,0 +1,14 @@
tests/cases/compiler/genericClassInheritsConstructorFromNonGenericClass.ts(1,17): error TS2686: A class must be declared after its base class.
tests/cases/compiler/genericClassInheritsConstructorFromNonGenericClass.ts(2,20): error TS2686: A class must be declared after its base class.
==== tests/cases/compiler/genericClassInheritsConstructorFromNonGenericClass.ts (2 errors) ====
class A extends B<string> { }
~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
class B<U> extends C { }
~
!!! error TS2686: A class must be declared after its base class.
class C {
constructor(p: string) { }
}
@@ -1,16 +0,0 @@
=== tests/cases/compiler/genericClassInheritsConstructorFromNonGenericClass.ts ===
class A extends B<string> { }
>A : Symbol(A, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 0, 0))
>B : Symbol(B, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 0, 29))
class B<U> extends C { }
>B : Symbol(B, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 0, 29))
>U : Symbol(U, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 1, 8))
>C : Symbol(C, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 1, 24))
class C {
>C : Symbol(C, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 1, 24))
constructor(p: string) { }
>p : Symbol(p, Decl(genericClassInheritsConstructorFromNonGenericClass.ts, 3, 16))
}
@@ -1,16 +0,0 @@
=== tests/cases/compiler/genericClassInheritsConstructorFromNonGenericClass.ts ===
class A extends B<string> { }
>A : A
>B : B<string>
class B<U> extends C { }
>B : B<U>
>U : U
>C : C
class C {
>C : C
constructor(p: string) { }
>p : string
}
@@ -1,8 +1,11 @@
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,22): error TS2686: A class must be declared after its base class.
tests/cases/compiler/missingPropertiesOfClassExpression.ts(1,52): error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (1 errors) ====
==== tests/cases/compiler/missingPropertiesOfClassExpression.ts (2 errors) ====
class George extends class { reset() { return this.y; } } {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
~
!!! error TS2339: Property 'y' does not exist on type '(Anonymous class)'.
constructor() {
@@ -1,11 +1,13 @@
tests/cases/compiler/privacyClassExtendsClauseDeclFile_GlobalFile.ts(16,67): error TS4020: Extends clause of exported class 'publicClassExtendingPrivateClassInModule' has or is using private name 'privateClassInPublicModule'.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(17,67): error TS4020: Extends clause of exported class 'publicClassExtendingPrivateClassInModule' has or is using private name 'privateClassInPublicModule'.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(20,63): error TS2686: A class must be declared after its base class.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(22,69): error TS4020: Extends clause of exported class 'publicClassExtendingFromPrivateModuleClass' has or is using private name 'privateModule'.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(22,69): error TS2686: A class must be declared after its base class.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(64,55): error TS4020: Extends clause of exported class 'publicClassExtendingPrivateClass' has or is using private name 'privateClass'.
tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(69,65): error TS4020: Extends clause of exported class 'publicClassExtendingFromPrivateModuleClass' has or is using private name 'privateModule'.
==== tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts (4 errors) ====
==== tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts (6 errors) ====
export module publicModule {
export class publicClassInPublicModule {
@@ -28,10 +30,14 @@ tests/cases/compiler/privacyClassExtendsClauseDeclFile_externalModule.ts(69,65):
}
class privateClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule {
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
}
export class publicClassExtendingFromPrivateModuleClass extends privateModule.publicClassInPrivateModule { // Should error
~~~~~~~~~~~~~
!!! error TS4020: Extends clause of exported class 'publicClassExtendingFromPrivateModuleClass' has or is using private name 'privateModule'.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
!!! error TS2686: A class must be declared after its base class.
}
}
File diff suppressed because it is too large Load Diff
@@ -1,8 +1,11 @@
tests/cases/conformance/es6/Symbols/symbolProperty33.ts(1,18): error TS2686: A class must be declared after its base class.
tests/cases/conformance/es6/Symbols/symbolProperty33.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
==== tests/cases/conformance/es6/Symbols/symbolProperty33.ts (1 errors) ====
==== tests/cases/conformance/es6/Symbols/symbolProperty33.ts (2 errors) ====
class C1 extends C2 {
~~
!!! error TS2686: A class must be declared after its base class.
[Symbol.toStringTag]() {
return { x: "" };
}
@@ -1,8 +1,11 @@
tests/cases/conformance/es6/Symbols/symbolProperty34.ts(1,18): error TS2686: A class must be declared after its base class.
tests/cases/conformance/es6/Symbols/symbolProperty34.ts(7,6): error TS1023: An index signature parameter type must be 'string' or 'number'.
==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (1 errors) ====
==== tests/cases/conformance/es6/Symbols/symbolProperty34.ts (2 errors) ====
class C1 extends C2 {
~~
!!! error TS2686: A class must be declared after its base class.
[Symbol.toStringTag]() {
return { x: "" };
}