File tree Expand file tree Collapse file tree 4 files changed +25
-72
lines changed Expand file tree Collapse file tree 4 files changed +25
-72
lines changed Original file line number Diff line number Diff line change @@ -6609,19 +6609,18 @@ export class Compiler extends DiagnosticEmitter {
66096609 for ( let i = 0 , k = overrideInstances . length ; i < k ; ++ i ) {
66106610 let overrideInstance = overrideInstances [ i ] ;
66116611 if ( ! overrideInstance . is ( CommonFlags . Compiled ) ) continue ; // errored
6612- let overrideType = overrideInstance . type ;
6613- let originalType = instance . type ;
66146612
6615- assert ( originalType . getSignature ( ) != null && overrideType . getSignature ( ) != null ) ;
6616- if ( ! ( overrideType . getSignature ( ) as Signature ) . isAssignableTo ( originalType . getSignature ( ) as Signature , true ) ) {
6613+ const overrideSignature = overrideInstance . signature ;
6614+ const originalSignature = instance . signature ;
6615+
6616+ if ( ! overrideSignature . isAssignableTo ( originalSignature , true ) ) {
66176617 this . error (
66186618 DiagnosticCode . Type_0_is_not_assignable_to_type_1 ,
6619- overrideInstance . identifierNode . range , overrideType . toString ( ) , originalType . toString ( )
6619+ overrideInstance . identifierNode . range , overrideSignature . toString ( ) , originalSignature . toString ( )
66206620 ) ;
66216621 continue ;
66226622 }
66236623 // TODO: additional optional parameters are not permitted by `isAssignableTo` yet
6624- let overrideSignature = overrideInstance . signature ;
66256624 let overrideParameterTypes = overrideSignature . parameterTypes ;
66266625 let overrideNumParameters = overrideParameterTypes . length ;
66276626 let paramExprs = new Array < ExpressionRef > ( 1 + overrideNumParameters ) ;
Original file line number Diff line number Diff line change @@ -1052,23 +1052,14 @@ export class Signature {
10521052 let thisThisType = this . thisType ;
10531053 let targetThisType = target . thisType ;
10541054
1055- if (
1056- ( thisThisType == null && targetThisType != null ) ||
1057- ( thisThisType != null && targetThisType == null )
1058- ) {
1059- return false ;
1060- } else if ( thisThisType != null && targetThisType != null ) {
1061- if ( checkCompatibleOverride ) {
1062- // check kind of `this` type
1063- if ( ! thisThisType . canExtendOrImplement ( targetThisType ) ) {
1064- return false ;
1065- }
1066- } else {
1067- // check `this` type (invariant)
1068- if ( ! targetThisType . isAssignableTo ( thisThisType ) ) {
1069- return false ;
1070- }
1055+ if ( thisThisType != null && targetThisType != null ) {
1056+ const compatibleThisType = checkCompatibleOverride ? thisThisType . canExtendOrImplement ( targetThisType )
1057+ : targetThisType . isAssignableTo ( thisThisType ) ;
1058+ if ( ! compatibleThisType ) {
1059+ return false ;
10711060 }
1061+ } else if ( thisThisType || targetThisType ) {
1062+ return false ;
10721063 }
10731064
10741065 // check rest parameter
Original file line number Diff line number Diff line change 11{
22 "asc_flags" : [],
33 "stderr" : [
4- " TS2322: Type '(this: class-member-function-as-parameter/C, i32 ) => i32 ' is not assignable to type '(i32 ) => i32 '." ,
5- " TS2322: Type '() => void' is not assignable to type '(this: class-member-function-as-parameter/B ) => void'." ,
4+ " TS2322: Type '() => void ' is not assignable to type '(this: class-member-function-as-parameter/A ) => void '." ,
5+ " TS2322: Type '(this: class-member-function-as-parameter/B ) => void' is not assignable to type '(this: class-member-function-as-parameter/A ) => void'." ,
66 " EOF"
77 ]
88}
Original file line number Diff line number Diff line change 1- class C {
2- aa : i32 = 1 ;
3- callback ( a : i32 ) : i32 {
4- return this . aa + a + 3 ;
5- }
6- }
7-
8- function expectCallback ( c1 : ( arg0 : i32 ) => i32 ) : i32 {
9- return c1 ( 4 ) ;
10- }
11-
12- export function fut ( ) : i32 {
13- const c1 = new C ( ) ;
14- return expectCallback ( c1 . callback ) ;
15- }
16-
17- fut ( ) ;
18-
191class A {
20- foo ( ) : void {
21- console . log ( "A" ) ;
22- }
2+ foo ( ) : void { }
233}
24-
254class B extends A {
26- foo ( ) : void {
27- console . log ( "B" ) ;
28- }
29- }
30-
31- function foo ( ) : void {
32- console . log ( "nothing" ) ;
33- }
34-
35- function consume ( callback : ( this : B ) => void ) : void {
36- const b = new B ( ) ;
37- callback . call ( b ) ;
38- }
39-
40- export function testNull ( ) : void {
41- consume ( foo ) ; // This should (and does) error; this is fine.
42- }
43-
44- export function testA ( ) : void {
45- const a = new A ( ) ;
46- consume ( a . foo ) ; // This shouldn't error
47- }
48-
49- testNull ( ) ;
50- testA ( ) ;
51-
5+ foo ( ) : void { }
6+ }
7+ function foo ( ) : void { }
8+ function consumeA ( callback : ( this : A ) => void ) : void { }
9+ function consumeB ( callback : ( this : B ) => void ) : void { }
10+ const a = new A ( ) ;
11+ const b = new B ( ) ;
12+ consumeB ( a . foo ) ; // shouldn't error
13+ consumeA ( foo ) ; // should error
14+ consumeA ( b . foo ) ; // should error
5215ERROR ( "EOF" ) ;
You can’t perform that action at this time.
0 commit comments