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
3 changes: 3 additions & 0 deletions internal/checker/checker.go
Original file line number Diff line number Diff line change
Expand Up @@ -18556,6 +18556,9 @@ func findIndexInfo(indexInfos []*IndexInfo, keyType *Type) *IndexInfo {
}

func (c *Checker) getBaseTypes(t *Type) []*Type {
if t.objectFlags&(ObjectFlagsClassOrInterface|ObjectFlagsReference) == 0 {
return nil
}
data := t.AsInterfaceType()
if !data.baseTypesResolved {
if !c.pushTypeResolution(t, TypeSystemPropertyNameResolvedBaseTypes) {
Expand Down
41 changes: 41 additions & 0 deletions testdata/baselines/reference/compiler/noCrashOnMixin2.errors.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
noCrashOnMixin2.ts(11,33): error TS2370: A rest parameter must be of an array type.
noCrashOnMixin2.ts(11,40): error TS1047: A rest parameter cannot be optional.
noCrashOnMixin2.ts(14,12): error TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'.
noCrashOnMixin2.ts(23,9): error TS2674: Constructor of class 'Abstract' is protected and only accessible within the class declaration.


==== noCrashOnMixin2.ts (4 errors) ====
// https://github.com/microsoft/TypeScript/issues/62921

class Abstract {
protected constructor() {
}
}

class Concrete extends Abstract {
}

type Constructor<T = {}> = new (...args?: any[]) => T;
~~~~~~~~~~~~~~~
!!! error TS2370: A rest parameter must be of an array type.
~
!!! error TS1047: A rest parameter cannot be optional.

function Mixin<TBase extends Constructor>(Base: TBase) {
return class extends Base {
~~~~~
!!! error TS2545: A mixin class must have a constructor with a single rest parameter of type 'any[]'.
};
}

class Empty {
}

class CrashTrigger extends Mixin(Empty) {
public trigger() {
new Concrete();
~~~~~~~~~~~~~~
!!! error TS2674: Constructor of class 'Abstract' is protected and only accessible within the class declaration.
}
}

53 changes: 53 additions & 0 deletions testdata/baselines/reference/compiler/noCrashOnMixin2.symbols
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//// [tests/cases/compiler/noCrashOnMixin2.ts] ////

=== noCrashOnMixin2.ts ===
// https://github.com/microsoft/TypeScript/issues/62921

class Abstract {
>Abstract : Symbol(Abstract, Decl(noCrashOnMixin2.ts, 0, 0))

protected constructor() {
}
}

class Concrete extends Abstract {
>Concrete : Symbol(Concrete, Decl(noCrashOnMixin2.ts, 5, 1))
>Abstract : Symbol(Abstract, Decl(noCrashOnMixin2.ts, 0, 0))
}

type Constructor<T = {}> = new (...args?: any[]) => T;
>Constructor : Symbol(Constructor, Decl(noCrashOnMixin2.ts, 8, 1))
>T : Symbol(T, Decl(noCrashOnMixin2.ts, 10, 17))
>args : Symbol(args, Decl(noCrashOnMixin2.ts, 10, 32))
>T : Symbol(T, Decl(noCrashOnMixin2.ts, 10, 17))

function Mixin<TBase extends Constructor>(Base: TBase) {
>Mixin : Symbol(Mixin, Decl(noCrashOnMixin2.ts, 10, 54))
>TBase : Symbol(TBase, Decl(noCrashOnMixin2.ts, 12, 15))
>Constructor : Symbol(Constructor, Decl(noCrashOnMixin2.ts, 8, 1))
>Base : Symbol(Base, Decl(noCrashOnMixin2.ts, 12, 42))
>TBase : Symbol(TBase, Decl(noCrashOnMixin2.ts, 12, 15))

return class extends Base {
>Base : Symbol(Base, Decl(noCrashOnMixin2.ts, 12, 42))

};
}

class Empty {
>Empty : Symbol(Empty, Decl(noCrashOnMixin2.ts, 15, 1))
}

class CrashTrigger extends Mixin(Empty) {
>CrashTrigger : Symbol(CrashTrigger, Decl(noCrashOnMixin2.ts, 18, 1))
>Mixin : Symbol(Mixin, Decl(noCrashOnMixin2.ts, 10, 54))
>Empty : Symbol(Empty, Decl(noCrashOnMixin2.ts, 15, 1))

public trigger() {
>trigger : Symbol(CrashTrigger.trigger, Decl(noCrashOnMixin2.ts, 20, 41))

new Concrete();
>Concrete : Symbol(Concrete, Decl(noCrashOnMixin2.ts, 5, 1))
}
}

51 changes: 51 additions & 0 deletions testdata/baselines/reference/compiler/noCrashOnMixin2.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
//// [tests/cases/compiler/noCrashOnMixin2.ts] ////

=== noCrashOnMixin2.ts ===
// https://github.com/microsoft/TypeScript/issues/62921

class Abstract {
>Abstract : Abstract

protected constructor() {
}
}

class Concrete extends Abstract {
>Concrete : Concrete
>Abstract : Abstract
}

type Constructor<T = {}> = new (...args?: any[]) => T;
>Constructor : Constructor<T>
>args : any[] | undefined

function Mixin<TBase extends Constructor>(Base: TBase) {
>Mixin : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
>Base : TBase

return class extends Base {
>class extends Base { } : { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
>Base : {}

};
}

class Empty {
>Empty : Empty
}

class CrashTrigger extends Mixin(Empty) {
>CrashTrigger : CrashTrigger
>Mixin(Empty) : Mixin.(Anonymous class)
>Mixin : <TBase extends Constructor<{}>>(Base: TBase) => { new (...args?: any[] | undefined): (Anonymous class); prototype: Mixin.(Anonymous class); } & TBase
>Empty : typeof Empty

public trigger() {
>trigger : () => void

new Concrete();
>new Concrete() : Concrete
>Concrete : typeof Concrete
}
}

28 changes: 28 additions & 0 deletions testdata/tests/cases/compiler/noCrashOnMixin2.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// @strict: true
// @noEmit: true

// https://github.com/microsoft/TypeScript/issues/62921

class Abstract {
protected constructor() {
}
}

class Concrete extends Abstract {
}

type Constructor<T = {}> = new (...args?: any[]) => T;

function Mixin<TBase extends Constructor>(Base: TBase) {
return class extends Base {
};
}

class Empty {
}

class CrashTrigger extends Mixin(Empty) {
public trigger() {
new Concrete();
}
}