Skip to content

Commit 1876c67

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Add test for forwarding stub targets
The added test show that we generate a super call to the wrong target in some forwarding stubs. The target should have been the mixed in member but is instead the super member that it overrides. Change-Id: If7536628370ba69405cbedef969e727a5d220058 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/170684 Reviewed-by: Dmitry Stefantsov <[email protected]> Commit-Queue: Johnni Winther <[email protected]>
1 parent 54cd996 commit 1876c67

15 files changed

+553
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2020, 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 Superclass {
6+
String method1(num argument1, num argument2) => "Superclass";
7+
String method2(num argument1, num argument2) => "Superclass";
8+
String method3(num argument1, covariant int argument2) => "Superclass";
9+
String method4(num argument1, covariant num argument2) => "Superclass";
10+
}
11+
12+
class Mixin {
13+
String method1(num argument1, num argument2) => "Mixin";
14+
String method2(covariant int argument1, num argument2) => "Mixin";
15+
String method3(num argument1, num argument2) => "Mixin";
16+
String method4(covariant int argument1, int argument2) => "Mixin";
17+
}
18+
19+
class Class extends Superclass with Mixin {}
20+
21+
main() {
22+
Class c = new Class();
23+
expect("Mixin", c.method1(0, 1));
24+
expect("Mixin", c.method2(0, 1));
25+
expect("Mixin", c.method3(0, 1));
26+
expect("Mixin", c.method4(0, 1));
27+
28+
Superclass s = c;
29+
expect("Mixin", s.method1(0.5, 1.5));
30+
throws(() => s.method2(0.5, 1.5));
31+
expect("Mixin", s.method3(0.5, 1));
32+
throws(() => s.method4(0.5, 1));
33+
expect("Mixin", s.method4(1, 0.5));
34+
35+
Mixin m = c;
36+
expect("Mixin", m.method1(0, 1));
37+
expect("Mixin", m.method2(0, 1));
38+
expect("Mixin", m.method3(0, 1));
39+
expect("Mixin", m.method4(0, 1));
40+
}
41+
42+
void expect(expected, actual) {
43+
if (expected != actual) throw 'Expected $expected, actual $actual';
44+
}
45+
46+
void throws(void Function() f) {
47+
try {
48+
f();
49+
} catch (_) {
50+
return;
51+
}
52+
throw 'Expected exception';
53+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class Superclass extends core::Object {
6+
synthetic constructor •() → self::Superclass*
7+
;
8+
method method1(core::num* argument1, core::num* argument2) → core::String*
9+
;
10+
method method2(core::num* argument1, core::num* argument2) → core::String*
11+
;
12+
method method3(core::num* argument1, covariant core::int* argument2) → core::String*
13+
;
14+
method method4(core::num* argument1, covariant core::num* argument2) → core::String*
15+
;
16+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
17+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
18+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
19+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
20+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
21+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
22+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
23+
abstract member-signature method toString() → core::String*; -> core::Object::toString
24+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
25+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
26+
}
27+
class Mixin extends core::Object {
28+
synthetic constructor •() → self::Mixin*
29+
;
30+
method method1(core::num* argument1, core::num* argument2) → core::String*
31+
;
32+
method method2(covariant core::int* argument1, core::num* argument2) → core::String*
33+
;
34+
method method3(core::num* argument1, core::num* argument2) → core::String*
35+
;
36+
method method4(covariant core::int* argument1, core::int* argument2) → core::String*
37+
;
38+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
39+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
40+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
41+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
42+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
43+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
44+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
45+
abstract member-signature method toString() → core::String*; -> core::Object::toString
46+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
47+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
48+
}
49+
abstract class _Class&Superclass&Mixin = self::Superclass with self::Mixin /*isAnonymousMixin*/ {
50+
synthetic constructor •() → self::_Class&Superclass&Mixin*
51+
: super self::Superclass::•()
52+
;
53+
abstract forwarding-stub method method2(covariant core::num* argument1, core::num* argument2) → core::String*;
54+
forwarding-stub method method3(core::num* argument1, covariant core::num* argument2) → core::String*
55+
return super.{self::Superclass::method3}(argument1, argument2);
56+
forwarding-stub method method4(covariant core::num* argument1, covariant core::num* argument2) → core::String*
57+
return super.{self::Superclass::method4}(argument1, argument2);
58+
}
59+
class Class extends self::_Class&Superclass&Mixin {
60+
synthetic constructor •() → self::Class*
61+
;
62+
}
63+
static method main() → dynamic
64+
;
65+
static method expect(dynamic expected, dynamic actual) → void
66+
;
67+
static method throws(() →* void f) → void
68+
;
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class Superclass extends core::Object {
6+
synthetic constructor •() → self::Superclass*
7+
: super core::Object::•()
8+
;
9+
method method1(core::num* argument1, core::num* argument2) → core::String*
10+
return "Superclass";
11+
method method2(core::num* argument1, core::num* argument2) → core::String*
12+
return "Superclass";
13+
method method3(core::num* argument1, covariant core::int* argument2) → core::String*
14+
return "Superclass";
15+
method method4(core::num* argument1, covariant core::num* argument2) → core::String*
16+
return "Superclass";
17+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
18+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
19+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
20+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
21+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
22+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
23+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
24+
abstract member-signature method toString() → core::String*; -> core::Object::toString
25+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
26+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
27+
}
28+
class Mixin extends core::Object {
29+
synthetic constructor •() → self::Mixin*
30+
: super core::Object::•()
31+
;
32+
method method1(core::num* argument1, core::num* argument2) → core::String*
33+
return "Mixin";
34+
method method2(covariant core::int* argument1, core::num* argument2) → core::String*
35+
return "Mixin";
36+
method method3(core::num* argument1, core::num* argument2) → core::String*
37+
return "Mixin";
38+
method method4(covariant core::int* argument1, core::int* argument2) → core::String*
39+
return "Mixin";
40+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
41+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
42+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
43+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
44+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
45+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
46+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
47+
abstract member-signature method toString() → core::String*; -> core::Object::toString
48+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
49+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
50+
}
51+
abstract class _Class&Superclass&Mixin = self::Superclass with self::Mixin /*isAnonymousMixin*/ {
52+
synthetic constructor •() → self::_Class&Superclass&Mixin*
53+
: super self::Superclass::•()
54+
;
55+
abstract forwarding-stub method method2(covariant core::num* argument1, core::num* argument2) → core::String*;
56+
forwarding-stub method method3(core::num* argument1, covariant core::num* argument2) → core::String*
57+
return super.{self::Superclass::method3}(argument1, argument2);
58+
forwarding-stub method method4(covariant core::num* argument1, covariant core::num* argument2) → core::String*
59+
return super.{self::Superclass::method4}(argument1, argument2);
60+
}
61+
class Class extends self::_Class&Superclass&Mixin {
62+
synthetic constructor •() → self::Class*
63+
: super self::_Class&Superclass&Mixin::•()
64+
;
65+
}
66+
static method main() → dynamic {
67+
self::Class* c = new self::Class::•();
68+
self::expect("Mixin", c.{self::Mixin::method1}(0, 1));
69+
self::expect("Mixin", c.{self::_Class&Superclass&Mixin::method2}(0, 1));
70+
self::expect("Mixin", c.{self::_Class&Superclass&Mixin::method3}(0, 1));
71+
self::expect("Mixin", c.{self::_Class&Superclass&Mixin::method4}(0, 1));
72+
self::Superclass* s = c;
73+
self::expect("Mixin", s.{self::Superclass::method1}(0.5, 1.5));
74+
self::throws(() → core::String* => s.{self::Superclass::method2}(0.5, 1.5));
75+
self::expect("Mixin", s.{self::Superclass::method3}(0.5, 1));
76+
self::throws(() → core::String* => s.{self::Superclass::method4}(0.5, 1));
77+
self::expect("Mixin", s.{self::Superclass::method4}(1, 0.5));
78+
self::Mixin* m = c;
79+
self::expect("Mixin", m.{self::Mixin::method1}(0, 1));
80+
self::expect("Mixin", m.{self::Mixin::method2}(0, 1));
81+
self::expect("Mixin", m.{self::Mixin::method3}(0, 1));
82+
self::expect("Mixin", m.{self::Mixin::method4}(0, 1));
83+
}
84+
static method expect(dynamic expected, dynamic actual) → void {
85+
if(!expected.{core::Object::==}(actual))
86+
throw "Expected ${expected}, actual ${actual}";
87+
}
88+
static method throws(() →* void f) → void {
89+
try {
90+
f.call();
91+
}
92+
on dynamic catch(final dynamic _) {
93+
return;
94+
}
95+
throw "Expected exception";
96+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Superclass {
2+
String method1(num argument1, num argument2) => "Superclass";
3+
String method2(num argument1, num argument2) => "Superclass";
4+
String method3(num argument1, covariant int argument2) => "Superclass";
5+
String method4(num argument1, covariant num argument2) => "Superclass";
6+
}
7+
8+
class Mixin {
9+
String method1(num argument1, num argument2) => "Mixin";
10+
String method2(covariant int argument1, num argument2) => "Mixin";
11+
String method3(num argument1, num argument2) => "Mixin";
12+
String method4(covariant int argument1, int argument2) => "Mixin";
13+
}
14+
15+
class Class extends Superclass with Mixin {}
16+
17+
main() {}
18+
void expect(expected, actual) {}
19+
void throws(void Function() f) {}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Class extends Superclass with Mixin {}
2+
3+
class Mixin {
4+
String method1(num argument1, num argument2) => "Mixin";
5+
String method2(covariant int argument1, num argument2) => "Mixin";
6+
String method3(num argument1, num argument2) => "Mixin";
7+
String method4(covariant int argument1, int argument2) => "Mixin";
8+
}
9+
10+
class Superclass {
11+
String method1(num argument1, num argument2) => "Superclass";
12+
String method2(num argument1, num argument2) => "Superclass";
13+
String method3(num argument1, covariant int argument2) => "Superclass";
14+
String method4(num argument1, covariant num argument2) => "Superclass";
15+
}
16+
17+
main() {}
18+
void expect(expected, actual) {}
19+
void throws(void Function() f) {}
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Copyright (c) 2020, 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 Superclass {
6+
String method1(num argument1, num argument2) => "Superclass";
7+
String method2(num argument1, num argument2) => "Superclass";
8+
String method3(num argument1, covariant int argument2) => "Superclass";
9+
String method4(num argument1, covariant num argument2) => "Superclass";
10+
}
11+
12+
class Mixin {
13+
String method1(num argument1, num argument2) => "Mixin";
14+
String method2(covariant int argument1, num argument2) => "Mixin";
15+
String method3(num argument1, num argument2) => "Mixin";
16+
String method4(covariant int argument1, int argument2) => "Mixin";
17+
}
18+
19+
class Class extends Superclass with Mixin {}
20+
21+
main() {
22+
Class c = new Class();
23+
expect("Mixin", c.method1(0, 1));
24+
expect("Mixin", c.method2(0, 1));
25+
expect("Mixin", c.method3(0, 1));
26+
expect("Mixin", c.method4(0, 1));
27+
28+
Superclass s = c;
29+
expect("Mixin", s.method1(0.5, 1.5));
30+
throws(() => s.method2(0.5, 1.5));
31+
expect("Mixin", s.method3(0.5, 1));
32+
throws(() => s.method4(0.5, 1));
33+
expect("Mixin", s.method4(1, 0.5));
34+
35+
Mixin m = c;
36+
expect("Mixin", m.method1(0, 1));
37+
expect("Mixin", m.method2(0, 1));
38+
expect("Mixin", m.method3(0, 1));
39+
expect("Mixin", m.method4(0, 1));
40+
}
41+
42+
void expect(expected, actual) {
43+
if (expected != actual) throw 'Expected $expected, actual $actual';
44+
}
45+
46+
void throws(void Function() f) {
47+
try {
48+
f();
49+
} catch (_) {
50+
return;
51+
}
52+
throw 'Expected exception';
53+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class Superclass extends core::Object {
6+
synthetic constructor •() → self::Superclass
7+
;
8+
method method1(core::num argument1, core::num argument2) → core::String
9+
;
10+
method method2(core::num argument1, core::num argument2) → core::String
11+
;
12+
method method3(core::num argument1, covariant core::int argument2) → core::String
13+
;
14+
method method4(core::num argument1, covariant core::num argument2) → core::String
15+
;
16+
}
17+
class Mixin extends core::Object {
18+
synthetic constructor •() → self::Mixin
19+
;
20+
method method1(core::num argument1, core::num argument2) → core::String
21+
;
22+
method method2(covariant core::int argument1, core::num argument2) → core::String
23+
;
24+
method method3(core::num argument1, core::num argument2) → core::String
25+
;
26+
method method4(covariant core::int argument1, core::int argument2) → core::String
27+
;
28+
}
29+
abstract class _Class&Superclass&Mixin = self::Superclass with self::Mixin /*isAnonymousMixin*/ {
30+
synthetic constructor •() → self::_Class&Superclass&Mixin
31+
: super self::Superclass::•()
32+
;
33+
abstract forwarding-stub method method2(covariant core::num argument1, core::num argument2) → core::String;
34+
forwarding-stub method method3(core::num argument1, covariant core::num argument2) → core::String
35+
return super.{self::Superclass::method3}(argument1, argument2);
36+
forwarding-stub method method4(covariant core::num argument1, covariant core::num argument2) → core::String
37+
return super.{self::Superclass::method4}(argument1, argument2);
38+
}
39+
class Class extends self::_Class&Superclass&Mixin {
40+
synthetic constructor •() → self::Class
41+
;
42+
}
43+
static method main() → dynamic
44+
;
45+
static method expect(dynamic expected, dynamic actual) → void
46+
;
47+
static method throws(() → void f) → void
48+
;

0 commit comments

Comments
 (0)