Skip to content
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
6 changes: 6 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15603,6 +15603,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
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Original file line number Diff line number Diff line change
Expand Up @@ -1943,6 +1943,10 @@
"category": "Error",
"code": 2689
},
"A class must be declared after its base class.": {
"category": "Error",
"code": 2690
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down
65 changes: 33 additions & 32 deletions tests/baselines/reference/baseTypeWrappingInstantiationChain.js
Original file line number Diff line number Diff line change
@@ -1,63 +1,50 @@
//// [baseTypeWrappingInstantiationChain.ts]
class C<T1> extends CBase<T1> {
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 CBaseBase<T3> {
constructor(x: Parameter<T3>) { }
}

class CBase<T2> extends CBaseBase<Wrapper<T2>> {

}

class CBaseBase<T3> {
constructor(x: Parameter<T3>) { }
}

class Parameter<T4> {
method(t: T4) { }
}

class Wrapper<T5> {
property: T5;
}
}

class C<T1> extends CBase<T1> {
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>) { }
}


//// [baseTypeWrappingInstantiationChain.js]
var __extends = (this && this.__extends) || function (d, b) {
for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p];
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
var C = (function (_super) {
__extends(C, _super);
function C() {
_super.apply(this, arguments);
var CBaseBase = (function () {
function CBaseBase(x) {
}
C.prototype.works = function () {
new CBaseBase(this);
};
C.prototype.alsoWorks = function () {
new CBase(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
};
C.prototype.method = function (t) { };
return C;
}(CBase));
return CBaseBase;
}());
var CBase = (function (_super) {
__extends(CBase, _super);
function CBase() {
_super.apply(this, arguments);
}
return CBase;
}(CBaseBase));
var CBaseBase = (function () {
function CBaseBase(x) {
}
return CBaseBase;
}());
var Parameter = (function () {
function Parameter() {
}
Expand All @@ -69,3 +56,17 @@ var Wrapper = (function () {
}
return Wrapper;
}());
var C = (function (_super) {
__extends(C, _super);
function C() {
_super.apply(this, arguments);
}
C.prototype.works = function () {
new CBaseBase(this);
};
C.prototype.alsoWorks = function () {
new CBase(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
};
C.prototype.method = function (t) { };
return C;
}(CBase));
105 changes: 53 additions & 52 deletions tests/baselines/reference/baseTypeWrappingInstantiationChain.symbols
Original file line number Diff line number Diff line change
@@ -1,69 +1,70 @@
=== 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))
}
class CBaseBase<T3> {
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 0, 16))

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))
constructor(x: Parameter<T3>) { }
>x : Symbol(x, Decl(baseTypeWrappingInstantiationChain.ts, 1, 16))
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 6, 1))
>T3 : Symbol(T3, Decl(baseTypeWrappingInstantiationChain.ts, 0, 16))
}

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))
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 4, 12))
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
>T2 : Symbol(T2, Decl(baseTypeWrappingInstantiationChain.ts, 4, 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))
>Parameter : Symbol(Parameter, Decl(baseTypeWrappingInstantiationChain.ts, 6, 1))
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 8, 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))
>method : Symbol(Parameter.method, Decl(baseTypeWrappingInstantiationChain.ts, 8, 21))
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 9, 11))
>T4 : Symbol(T4, Decl(baseTypeWrappingInstantiationChain.ts, 8, 16))
}

class Wrapper<T5> {
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 21, 1))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 12, 14))

property: T5;
>property : Symbol(Wrapper.property, Decl(baseTypeWrappingInstantiationChain.ts, 23, 19))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 23, 14))
>property : Symbol(Wrapper.property, Decl(baseTypeWrappingInstantiationChain.ts, 12, 19))
>T5 : Symbol(T5, Decl(baseTypeWrappingInstantiationChain.ts, 12, 14))
}

class C<T1> extends CBase<T1> {
>C : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))

public works() {
>works : Symbol(C.works, Decl(baseTypeWrappingInstantiationChain.ts, 16, 31))

new CBaseBase<Wrapper<T1>>(this);
>CBaseBase : Symbol(CBaseBase, Decl(baseTypeWrappingInstantiationChain.ts, 0, 0))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
}
public alsoWorks() {
>alsoWorks : Symbol(C.alsoWorks, Decl(baseTypeWrappingInstantiationChain.ts, 19, 5))

new CBase<T1>(this); // Should not error, parameter is of type Parameter<Wrapper<T1>>
>CBase : Symbol(CBase, Decl(baseTypeWrappingInstantiationChain.ts, 2, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
>this : Symbol(C, Decl(baseTypeWrappingInstantiationChain.ts, 14, 1))
}

public method(t: Wrapper<T1>) { }
>method : Symbol(C.method, Decl(baseTypeWrappingInstantiationChain.ts, 22, 5))
>t : Symbol(t, Decl(baseTypeWrappingInstantiationChain.ts, 24, 18))
>Wrapper : Symbol(Wrapper, Decl(baseTypeWrappingInstantiationChain.ts, 10, 1))
>T1 : Symbol(T1, Decl(baseTypeWrappingInstantiationChain.ts, 16, 8))
}

75 changes: 38 additions & 37 deletions tests/baselines/reference/baseTypeWrappingInstantiationChain.types
Original file line number Diff line number Diff line change
@@ -1,4 +1,42 @@
=== tests/cases/compiler/baseTypeWrappingInstantiationChain.ts ===
class CBaseBase<T3> {
>CBaseBase : CBaseBase<T3>
>T3 : T3

constructor(x: Parameter<T3>) { }
>x : Parameter<T3>
>Parameter : Parameter<T4>
>T3 : T3
}

class CBase<T2> extends CBaseBase<Wrapper<T2>> {
>CBase : CBase<T2>
>T2 : T2
>CBaseBase : CBaseBase<Wrapper<T2>>
>Wrapper : Wrapper<T5>
>T2 : T2

}

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
}

class C<T1> extends CBase<T1> {
>C : C<T1>
>T1 : T1
Expand Down Expand Up @@ -32,40 +70,3 @@ class C<T1> extends CBase<T1> {
>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
}
25 changes: 25 additions & 0 deletions tests/baselines/reference/circularImportAlias.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
tests/cases/conformance/internalModules/importDeclarations/circularImportAlias.ts(5,28): error TS2690: 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 TS2690: 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();



Loading