Skip to content

Commit 236ea5b

Browse files
stereotype441commit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
Add further test cases reflecting the consensus on #31596.
Change-Id: Ib67f8ae239b89bf56efc059054b6430e27a0e66f Reviewed-on: https://dart-review.googlesource.com/34922 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
1 parent 6ae065b commit 236ea5b

10 files changed

+290
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
class A {}
8+
9+
class B extends A {}
10+
11+
class B2 extends A {}
12+
13+
class C {
14+
void f(covariant B x) {}
15+
}
16+
17+
abstract class I {
18+
void f(A x);
19+
}
20+
21+
// This class does not require a forwarding stub; the interface of D.f is (A) ->
22+
// void and the implementation has signature (covariant B) -> void. The
23+
// implementation satisfies the interface thanks to the presence of the
24+
// "covariant" keyword.
25+
class D extends C implements I {}
26+
27+
main() {
28+
var d = new D();
29+
I i = d;
30+
A a = new A();
31+
B b = new B();
32+
B2 b2Null = null;
33+
34+
// The following two lines are statically ok because the type B2 is assignable
35+
// to the type A. There should be no runtime error because the actual value
36+
// at runtime is `null`, which may be assigned to A.
37+
d.f(b2Null);
38+
i.f(b2Null);
39+
40+
void Function(Object) g = d.f; // Ok; D.f reified as (Object) -> void
41+
Expect.throwsTypeError(() {
42+
d.f(a);
43+
});
44+
Expect.throwsTypeError(() {
45+
i.f(a);
46+
});
47+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
class I0 {}
6+
7+
class A {}
8+
9+
class B extends A implements I0 {}
10+
11+
class B2 extends A {}
12+
13+
class C {
14+
void f(B x) {}
15+
}
16+
17+
abstract class I1 {
18+
void f(covariant A x);
19+
}
20+
21+
// This class contains a forwarding stub for f to allow it to satisfy the
22+
// interface I, while still ensuring that the x argument is type checked before
23+
// C.f is executed.
24+
//
25+
// For purposes of override checking, the forwarding stub is ignored.
26+
class D extends C implements I1 {}
27+
28+
class Test extends D {
29+
// Valid override - A assignable to A and B
30+
void f(A x) {} //# 01: ok
31+
void f(covariant A x) {} //# 02: ok
32+
33+
// Valid override - B assignable to A and B
34+
void f(B x) {} //# 03: ok
35+
void f(covariant B x) {} //# 04: ok
36+
37+
// Invalid override - I0 not assignable to A
38+
void f(I0 x) {} //# 05: compile-time error
39+
void f(covariant I0 x) {} //# 06: compile-time error
40+
41+
// Invalid override - B2 not assignable to B
42+
void f(B2 x) {} //# 07: compile-time error
43+
void f(covariant B2 x) {} //# 08: compile-time error
44+
}
45+
46+
main() {
47+
// Make sure that Test is compiled.
48+
new Test();
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
class I0 {}
8+
9+
class A {}
10+
11+
class B extends A implements I0 {}
12+
13+
class B2 extends A {}
14+
15+
class C {
16+
void f(B x) {}
17+
}
18+
19+
abstract class I {
20+
void f(covariant A x);
21+
}
22+
23+
// This class contains a forwarding stub for f to allow it to satisfy the
24+
// interface I, while still ensuring that the x argument is type checked before
25+
// C.f is executed.
26+
//
27+
// Super calls in a derived class resolve directly to C.f, and are type checked
28+
// accordingly at compile time.
29+
class D extends C implements I {}
30+
31+
class E extends D {
32+
void test() {
33+
I0 i0 = null;
34+
B2 b2 = null;
35+
36+
// ok since I0 is assignable to B
37+
super.f(i0); //# 01: ok
38+
39+
// not ok since B2 is not assignable to B
40+
super.f(b2); //# 02: compile-time error
41+
42+
var superF = super.f; // Inferred type: (B) -> void
43+
44+
// ok since I0 is assignable to B
45+
superF(i0); //# 03: ok
46+
47+
// not ok since B2 is not assignable to B
48+
superF(b2); //# 04: compile-time error
49+
50+
// Should pass since superF's runtime type is (B) -> void
51+
Expect.isTrue(superF is void Function(B)); //# 05: ok
52+
Expect.isTrue(superF is! void Function(I0)); //# 05: continued
53+
Expect.isTrue(superF is! void Function(A)); //# 05: continued
54+
Expect.isTrue(superF is! void Function(Object)); //# 05: continued
55+
}
56+
}
57+
58+
main() {
59+
new E().test();
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) 2018, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import "package:expect/expect.dart";
6+
7+
class A {}
8+
9+
class B extends A {}
10+
11+
class B2 extends A {}
12+
13+
class C {
14+
void f(B x) {}
15+
}
16+
17+
abstract class I {
18+
void f(covariant A x);
19+
}
20+
21+
// This class contains a forwarding stub for f to allow it to satisfy the
22+
// interface I, while still ensuring that the x argument is type checked before
23+
// C.f is executed.
24+
//
25+
// For purposes of static type checking, the interface of the class D is
26+
// considered to contain a method f with signature (A) -> void. For purposes of
27+
// runtime behavior, a tearoff of D.f is considered to have the reified runtime
28+
// type (Object) -> void.
29+
class D extends C implements I {}
30+
31+
main() {
32+
var d = new D();
33+
B2 b2Null = null;
34+
B2 b2 = new B2();
35+
36+
// Since the compile-time type of D.f is (A) -> void, it is assignable to (B2)
37+
// -> void. Since the runtime type is (Object) -> void, the assignment is
38+
// allowed at runtime as well.
39+
void Function(B2) g = d.f;
40+
41+
// However, the tear-off performs a runtime check of its argument, so it
42+
// accepts a value of `null`, but it does not accept a value whose runtime
43+
// type is B2.
44+
g(b2Null);
45+
Expect.throwsTypeError(() {
46+
g(b2);
47+
});
48+
}

tests/language_2/language_2_analyzer.status

+17
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,17 @@ instantiate_type_variable_test/01: CompileTimeError
10561056
int64_literal_test/03: MissingCompileTimeError # http://dartbug.com/31479
10571057
int64_literal_test/30: MissingCompileTimeError # http://dartbug.com/31479
10581058
interceptor6_test: CompileTimeError
1059+
issue31596_implement_covariant_test: CompileTimeError
1060+
issue31596_override_test/01: CompileTimeError
1061+
issue31596_override_test/02: CompileTimeError
1062+
issue31596_override_test/03: CompileTimeError
1063+
issue31596_override_test/04: CompileTimeError
1064+
issue31596_override_test/none: CompileTimeError
1065+
issue31596_super_test/01: CompileTimeError
1066+
issue31596_super_test/03: CompileTimeError
1067+
issue31596_super_test/05: CompileTimeError
1068+
issue31596_super_test/none: CompileTimeError
1069+
issue31596_tearoff_test: CompileTimeError
10591070
issue31596_test: CompileTimeError
10601071
malformed2_test: Pass, MissingCompileTimeError # Issue 31056.
10611072
mixin_super_2_test/01: MissingCompileTimeError
@@ -1384,6 +1395,12 @@ invalid_cast_test/10: MissingCompileTimeError
13841395
invalid_cast_test/11: MissingCompileTimeError
13851396
invocation_mirror_test: StaticWarning
13861397
issue13179_test: StaticWarning
1398+
issue31596_override_test/05: MissingCompileTimeError
1399+
issue31596_override_test/06: MissingCompileTimeError
1400+
issue31596_override_test/07: MissingCompileTimeError
1401+
issue31596_override_test/08: MissingCompileTimeError
1402+
issue31596_super_test/02: MissingCompileTimeError
1403+
issue31596_super_test/04: MissingCompileTimeError
13871404
known_identifier_prefix_error_test/*: MissingCompileTimeError # Error only in strong mode.
13881405
known_identifier_prefix_error_test/none: Pass
13891406
least_upper_bound_expansive_test/01: MissingCompileTimeError

tests/language_2/language_2_dart2js.status

+18
Original file line numberDiff line numberDiff line change
@@ -1033,6 +1033,7 @@ invalid_cast_test/08: MissingCompileTimeError
10331033
invalid_cast_test/09: MissingCompileTimeError
10341034
invalid_cast_test/10: MissingCompileTimeError
10351035
invalid_cast_test/11: MissingCompileTimeError
1036+
issue31596_super_test/05: RuntimeError
10361037
many_generic_instanceof_test: RuntimeError
10371038
map_literal8_test: RuntimeError
10381039
mixin_forwarding_constructor4_test/01: MissingCompileTimeError # Issue 15101
@@ -1542,6 +1543,15 @@ implicit_downcast_during_static_method_invocation_test: RuntimeError
15421543
implicit_downcast_during_super_method_invocation_test: RuntimeError
15431544
implicit_downcast_during_variable_declaration_test: RuntimeError
15441545
implicit_downcast_during_while_statement_test: RuntimeError
1546+
issue31596_implement_covariant_test: RuntimeError
1547+
issue31596_override_test/05: MissingCompileTimeError
1548+
issue31596_override_test/06: MissingCompileTimeError
1549+
issue31596_override_test/07: MissingCompileTimeError
1550+
issue31596_override_test/08: MissingCompileTimeError
1551+
issue31596_super_test/02: MissingCompileTimeError
1552+
issue31596_super_test/04: MissingCompileTimeError
1553+
issue31596_super_test/05: RuntimeError
1554+
issue31596_tearoff_test: RuntimeError
15451555
issue31596_test: RuntimeError
15461556

15471557
[ $compiler == dart2js && !$checked && !$dart2js_with_kernel ]
@@ -1564,6 +1574,7 @@ forwarding_stub_tearoff_generic_test: RuntimeError
15641574
forwarding_stub_tearoff_test: RuntimeError
15651575
function_subtype_inline2_test: RuntimeError
15661576
generic_test: RuntimeError, OK
1577+
issue31596_implement_covariant_test: RuntimeError
15671578
issue31596_test: RuntimeError
15681579
list_literal1_test/01: MissingCompileTimeError
15691580

@@ -3667,6 +3678,13 @@ instantiate_tearoff_of_call_test: RuntimeError
36673678
instantiate_tearoff_test: RuntimeError
36683679
integer_division_by_zero_test: RuntimeError # Issue 8301
36693680
invocation_mirror2_test: RuntimeError # Issue 6490 (wrong retval).
3681+
issue31596_override_test/05: MissingCompileTimeError
3682+
issue31596_override_test/06: MissingCompileTimeError
3683+
issue31596_override_test/07: MissingCompileTimeError
3684+
issue31596_override_test/08: MissingCompileTimeError
3685+
issue31596_super_test/02: MissingCompileTimeError
3686+
issue31596_super_test/04: MissingCompileTimeError
3687+
issue31596_tearoff_test: RuntimeError
36703688
left_shift_test: RuntimeError # Issue 1533
36713689
list_literal4_test/00: MissingCompileTimeError
36723690
list_literal4_test/01: MissingCompileTimeError

tests/language_2/language_2_dartdevc.status

+19
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,17 @@ instantiate_tearoff_of_call_test: RuntimeError
6161
instantiate_tearoff_test: RuntimeError
6262
interface_test/00: MissingCompileTimeError
6363
internal_library_test/01: MissingCompileTimeError # Issue 29920
64+
issue31596_implement_covariant_test: CompileTimeError
65+
issue31596_override_test/01: CompileTimeError
66+
issue31596_override_test/02: CompileTimeError
67+
issue31596_override_test/03: CompileTimeError
68+
issue31596_override_test/04: CompileTimeError
69+
issue31596_override_test/none: CompileTimeError
70+
issue31596_super_test/01: CompileTimeError
71+
issue31596_super_test/03: CompileTimeError
72+
issue31596_super_test/05: CompileTimeError
73+
issue31596_super_test/none: CompileTimeError
74+
issue31596_tearoff_test: CompileTimeError
6475
issue31596_test: CompileTimeError
6576
method_override_test: CompileTimeError # Negative test
6677
mixin_super_2_test/01: MissingCompileTimeError
@@ -363,6 +374,14 @@ instance_call_wrong_argument_count_negative_test: Fail
363374
instantiate_tearoff_of_call_test: CompileTimeError
364375
invocation_mirror_test: CompileTimeError # Issue 31402 Error: A value of type 'dart.core::int' can't be assigned to a variable of type 'dart.core::Invocation'.
365376
issue18628_2_test/01: MissingCompileTimeError
377+
issue31596_override_test/07: MissingCompileTimeError
378+
issue31596_override_test/08: MissingCompileTimeError
379+
issue31596_super_test/01: CompileTimeError
380+
issue31596_super_test/02: MissingCompileTimeError
381+
issue31596_super_test/03: CompileTimeError
382+
issue31596_super_test/04: MissingCompileTimeError
383+
issue31596_super_test/05: RuntimeError
384+
issue31596_tearoff_test: RuntimeError
366385
issue31596_test: RuntimeError
367386
issue_25671a_test/01: CompileTimeError # Warning: The method 'A::noSuchMethod' has fewer positional arguments than those of overridden method 'Object::noSuchMethod'.
368387
issue_25671b_test/01: CompileTimeError # Warning: The method 'A::noSuchMethod' has fewer positional arguments than those of overridden method 'Object::noSuchMethod'.

tests/language_2/language_2_kernel.status

+14
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,13 @@ initializing_formal_type_annotation_test/02: MissingCompileTimeError
466466
instantiate_tearoff_of_call_test: CompileTimeError
467467
invocation_mirror_test: CompileTimeError # Issue 31402 (Invocation arguments)
468468
issue18628_2_test/01: MissingCompileTimeError
469+
issue31596_override_test/07: MissingCompileTimeError
470+
issue31596_override_test/08: MissingCompileTimeError
471+
issue31596_super_test/01: CompileTimeError
472+
issue31596_super_test/02: MissingCompileTimeError
473+
issue31596_super_test/03: CompileTimeError
474+
issue31596_super_test/04: MissingCompileTimeError
475+
issue31596_super_test/05: RuntimeError
469476
issue_1751477_test: CompileTimeError # KernelVM bug: Deferred loading kernel issue 28335.
470477
issue_25671a_test/01: CompileTimeError # Test assumes Dart 1.0 semantics
471478
issue_25671b_test/01: DartkCrash
@@ -1317,6 +1324,13 @@ invocation_mirror_invoke_on_test: SkipByDesign
13171324
invocation_mirror_test: CompileTimeError # Issue 31402 (Invocation arguments)
13181325
issue18628_2_test/01: MissingCompileTimeError
13191326
issue21079_test: SkipByDesign
1327+
issue31596_override_test/07: MissingCompileTimeError
1328+
issue31596_override_test/08: MissingCompileTimeError
1329+
issue31596_super_test/01: CompileTimeError
1330+
issue31596_super_test/02: MissingCompileTimeError
1331+
issue31596_super_test/03: CompileTimeError
1332+
issue31596_super_test/04: MissingCompileTimeError
1333+
issue31596_super_test/05: RuntimeError
13201334
issue_1751477_test: CompileTimeError # KernelVM bug: Deferred loading kernel issue 28335.
13211335
issue_25671a_test/01: CompileTimeError # Test assumes Dart 1.0 semantics
13221336
issue_25671b_test/01: Crash

tests/language_2/language_2_precompiled.status

+9
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,14 @@ invocation_mirror2_test: SkipByDesign
486486
invocation_mirror_invoke_on2_test: SkipByDesign
487487
invocation_mirror_invoke_on_test: SkipByDesign
488488
issue21079_test: SkipByDesign
489+
issue31596_override_test/05: MissingCompileTimeError
490+
issue31596_override_test/06: MissingCompileTimeError
491+
issue31596_override_test/07: MissingCompileTimeError
492+
issue31596_override_test/08: MissingCompileTimeError
493+
issue31596_super_test/02: MissingCompileTimeError
494+
issue31596_super_test/04: MissingCompileTimeError
495+
issue31596_super_test/05: RuntimeError
496+
issue31596_tearoff_test: RuntimeError
489497
language_2/least_upper_bound_expansive_test/none: CompileTimeError
490498
least_upper_bound_expansive_test/none: CompileTimeError
491499
least_upper_bound_test/03: MissingCompileTimeError
@@ -1094,6 +1102,7 @@ implicit_downcast_during_super_initializer_test: RuntimeError
10941102
implicit_downcast_during_super_method_invocation_test: RuntimeError
10951103
implicit_downcast_during_variable_declaration_test: RuntimeError
10961104
implicit_downcast_during_while_statement_test: RuntimeError
1105+
issue31596_implement_covariant_test: RuntimeError
10971106
issue31596_test: RuntimeError
10981107
tearoff_dynamic_test: RuntimeError
10991108
type_argument_in_super_type_test: RuntimeError

tests/language_2/language_2_vm.status

+9
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,14 @@ invalid_cast_test/08: MissingCompileTimeError
478478
invalid_cast_test/09: MissingCompileTimeError
479479
invalid_cast_test/10: MissingCompileTimeError
480480
invalid_cast_test/11: MissingCompileTimeError
481+
issue31596_override_test/05: MissingCompileTimeError
482+
issue31596_override_test/06: MissingCompileTimeError
483+
issue31596_override_test/07: MissingCompileTimeError
484+
issue31596_override_test/08: MissingCompileTimeError
485+
issue31596_super_test/02: MissingCompileTimeError
486+
issue31596_super_test/04: MissingCompileTimeError
487+
issue31596_super_test/05: RuntimeError
488+
issue31596_tearoff_test: RuntimeError
481489
least_upper_bound_expansive_test/none: CompileTimeError
482490
least_upper_bound_test/03: MissingCompileTimeError
483491
least_upper_bound_test/04: MissingCompileTimeError
@@ -1137,6 +1145,7 @@ implicit_downcast_during_super_method_invocation_test: RuntimeError
11371145
implicit_downcast_during_variable_declaration_test: RuntimeError
11381146
implicit_downcast_during_while_statement_test: RuntimeError
11391147
inferrer_synthesized_constructor_test: RuntimeError
1148+
issue31596_implement_covariant_test: RuntimeError
11401149
issue31596_test: RuntimeError
11411150
list_literal1_test/01: MissingCompileTimeError
11421151
malformed2_test/00: MissingCompileTimeError

0 commit comments

Comments
 (0)