Skip to content

Commit 3e5d1d8

Browse files
committed
Fix function subtyping crash
Fixes #588 BUG= [email protected] Review URL: https://codereview.chromium.org/2069653003 .
1 parent 5c67ae3 commit 3e5d1d8

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

pkg/dev_compiler/lib/runtime/dart_sdk.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,6 +1567,9 @@ dart_library.library('dart_sdk', null, /* Imports */[
15671567
if (ft2 === core.Function) {
15681568
return true;
15691569
}
1570+
if (ft1 === core.Function) {
1571+
return false;
1572+
}
15701573
let ret1 = ft1.returnType;
15711574
let ret2 = ft2.returnType;
15721575
let args1 = ft1.args;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import "package:expect/expect.dart";
2+
3+
// regression test for ddc #588
4+
5+
typedef int Int2Int(int x);
6+
7+
void foo(List<Int2Int> list) {
8+
list.forEach((f) => print(f(42)));
9+
}
10+
11+
void main() {
12+
var l = <Function>[];
13+
Expect.throws(() => foo(l), (e) => e is TypeError);
14+
}

pkg/dev_compiler/tool/input_sdk/private/ddc_runtime/types.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ isFunctionSubtype(ft1, ft2, covariant) => JS('', '''(() => {
496496
return true;
497497
}
498498
499+
if ($ft1 === $Function) {
500+
return false;
501+
}
502+
499503
let ret1 = $ft1.returnType;
500504
let ret2 = $ft2.returnType;
501505

0 commit comments

Comments
 (0)