File tree 4 files changed +25
-72
lines changed
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 {
6609
6609
for ( let i = 0 , k = overrideInstances . length ; i < k ; ++ i ) {
6610
6610
let overrideInstance = overrideInstances [ i ] ;
6611
6611
if ( ! overrideInstance . is ( CommonFlags . Compiled ) ) continue ; // errored
6612
- let overrideType = overrideInstance . type ;
6613
- let originalType = instance . type ;
6614
6612
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 ) ) {
6617
6617
this . error (
6618
6618
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 ( )
6620
6620
) ;
6621
6621
continue ;
6622
6622
}
6623
6623
// TODO: additional optional parameters are not permitted by `isAssignableTo` yet
6624
- let overrideSignature = overrideInstance . signature ;
6625
6624
let overrideParameterTypes = overrideSignature . parameterTypes ;
6626
6625
let overrideNumParameters = overrideParameterTypes . length ;
6627
6626
let paramExprs = new Array < ExpressionRef > ( 1 + overrideNumParameters ) ;
Original file line number Diff line number Diff line change @@ -1052,23 +1052,14 @@ export class Signature {
1052
1052
let thisThisType = this . thisType ;
1053
1053
let targetThisType = target . thisType ;
1054
1054
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 ;
1071
1060
}
1061
+ } else if ( thisThisType || targetThisType ) {
1062
+ return false ;
1072
1063
}
1073
1064
1074
1065
// check rest parameter
Original file line number Diff line number Diff line change 1
1
{
2
2
"asc_flags" : [],
3
3
"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'." ,
6
6
" EOF"
7
7
]
8
8
}
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
-
19
1
class A {
20
- foo ( ) : void {
21
- console . log ( "A" ) ;
22
- }
2
+ foo ( ) : void { }
23
3
}
24
-
25
4
class 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
52
15
ERROR ( "EOF" ) ;
You can’t perform that action at this time.
0 commit comments