Skip to content

Commit 934136d

Browse files
Dmitry Stefantsovcommit-bot@chromium.org
Dmitry Stefantsov
authored andcommitted
[cfe] Don't perform generic tear-off type check in opt-out code
Change-Id: I168eef4594fb7c54e1eabc52ba8f0e8d6c4e6b03 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/209560 Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Erik Ernst <[email protected]> Commit-Queue: Dmitry Stefantsov <[email protected]>
1 parent d7c0271 commit 934136d

12 files changed

+149
-11
lines changed

pkg/front_end/lib/src/fasta/kernel/inference_visitor.dart

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4787,11 +4787,13 @@ class InferenceVisitor
47874787
!isThisReceiver) {
47884788
Member interfaceMember = readTarget.member!;
47894789
if (interfaceMember is Procedure) {
4790+
DartType typeToCheck = inferrer.isNonNullableByDefault
4791+
? interfaceMember.function
4792+
.computeFunctionType(inferrer.library.nonNullable)
4793+
: interfaceMember.function.returnType;
47904794
checkReturn =
47914795
TypeInferrerImpl.returnedTypeParametersOccurNonCovariantly(
4792-
interfaceMember.enclosingClass!,
4793-
interfaceMember.function
4794-
.computeFunctionType(inferrer.library.nonNullable));
4796+
interfaceMember.enclosingClass!, typeToCheck);
47954797
} else if (interfaceMember is Field) {
47964798
checkReturn =
47974799
TypeInferrerImpl.returnedTypeParametersOccurNonCovariantly(

pkg/front_end/testcases/general/bug33298.dart.weak.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static method test() → dynamic {
6565
core::List<core::String*>* list1 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(a.{self::A::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6666
core::List<core::String*>* list2 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(let final self::A* #t1 = a in #t1 == null ?{(core::String*) →* core::String*} null : #t1.{self::A::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6767
self::B<core::String*>* b = new self::B::•<core::String*>();
68-
core::List<core::String*>* list3 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(b.{self::B::call}{(core::String*) →* core::String*} as{TypeError,CovarianceCheck} (core::String*) →* core::String*){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
68+
core::List<core::String*>* list3 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(b.{self::B::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6969
core::List<core::String*>* list4 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(let final self::B<core::String*>* #t2 = b in #t2 == null ?{(core::String*) →* core::String*} null : #t2.{self::B::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
7070
self::C* c = new self::C::•();
7171
core::List<core::String*>* list5 = <core::String*>["a", "b", "c"].{core::Iterable::map}<core::String*>(c.{self::C::call}{<T extends core::Object* = dynamic>(T*) →* T*}<core::String*>){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};

pkg/front_end/testcases/general/bug33298.dart.weak.transformed.expect

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static method test() → dynamic {
6565
core::List<core::String*>* list1 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(a.{self::A::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6666
core::List<core::String*>* list2 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(let final self::A* #t1 = a in #t1 == null ?{(core::String*) →* core::String*} null : #t1.{self::A::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6767
self::B<core::String*>* b = new self::B::•<core::String*>();
68-
core::List<core::String*>* list3 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(b.{self::B::call}{(core::String*) →* core::String*} as{TypeError,CovarianceCheck} (core::String*) →* core::String*){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
68+
core::List<core::String*>* list3 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(b.{self::B::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
6969
core::List<core::String*>* list4 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(let final self::B<core::String*>* #t2 = b in #t2 == null ?{(core::String*) →* core::String*} null : #t2.{self::B::call}{(core::String*) →* core::String*}){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
7070
self::C* c = new self::C::•();
7171
core::List<core::String*>* list5 = core::_GrowableList::_literal3<core::String*>("a", "b", "c").{core::Iterable::map}<core::String*>(c.{self::C::call}{<T extends core::Object* = dynamic>(T*) →* T*}<core::String*>){((core::String*) →* core::String*) →* core::Iterable<core::String*>*}.{core::Iterable::toList}(){({growable: core::bool*}) →* core::List<core::String*>*};
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2021, 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+
// @dart=2.6
6+
7+
class A<X extends num> {
8+
void f<Y extends X>(Y y) {}
9+
}
10+
11+
expectThrows(void Function() f) {
12+
try {
13+
f();
14+
} catch (e) {
15+
return;
16+
}
17+
throw "Expected an exception to be thrown!";
18+
}
19+
20+
main() {
21+
A<num> a = new A<int>();
22+
void Function<Y extends num>(Y) f = a.f;
23+
expectThrows(() {
24+
f(3.14);
25+
});
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @dart = 2.6
2+
class A<X extends num> {
3+
void f<Y extends X>(Y y) {}
4+
}
5+
6+
expectThrows(void Function() f) {}
7+
main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// @dart = 2.6
2+
class A<X extends num> {
3+
void f<Y extends X>(Y y) {}
4+
}
5+
6+
expectThrows(void Function() f) {}
7+
main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A<X extends core::num*> extends core::Object {
6+
synthetic constructor •() → self::A<self::A::X*>*
7+
: super core::Object::•()
8+
;
9+
method f<generic-covariant-impl Y extends self::A::X*>(self::A::f::Y* y) → void {}
10+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
11+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
12+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
13+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
14+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
15+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
16+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
17+
abstract member-signature method toString() → core::String*; -> core::Object::toString
18+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
19+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
20+
}
21+
static method expectThrows(() →* void f) → dynamic {
22+
try {
23+
f(){() →* void};
24+
}
25+
on dynamic catch(final dynamic e) {
26+
return;
27+
}
28+
throw "Expected an exception to be thrown!";
29+
}
30+
static method main() → dynamic {
31+
self::A<core::num*>* a = new self::A::•<core::int*>();
32+
<Y extends core::num*>(Y*) →* void f = a.{self::A::f}{<generic-covariant-impl Y extends core::num*>(Y*) →* void};
33+
self::expectThrows(() → Null {
34+
f<core::double*>(3.14){(core::double*) →* void};
35+
});
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A<X extends core::num*> extends core::Object {
6+
synthetic constructor •() → self::A<self::A::X*>*
7+
;
8+
method f<generic-covariant-impl Y extends self::A::X*>(self::A::f::Y* y) → void
9+
;
10+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
11+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
12+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
13+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
14+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
15+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
16+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
17+
abstract member-signature method toString() → core::String*; -> core::Object::toString
18+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
19+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
20+
}
21+
static method expectThrows(() →* void f) → dynamic
22+
;
23+
static method main() → dynamic
24+
;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
class A<X extends core::num*> extends core::Object {
6+
synthetic constructor •() → self::A<self::A::X*>*
7+
: super core::Object::•()
8+
;
9+
method f<generic-covariant-impl Y extends self::A::X*>(self::A::f::Y* y) → void {}
10+
abstract member-signature get _identityHashCode() → core::int*; -> core::Object::_identityHashCode
11+
abstract member-signature method _instanceOf(dynamic instantiatorTypeArguments, dynamic functionTypeArguments, dynamic type) → core::bool*; -> core::Object::_instanceOf
12+
abstract member-signature method _simpleInstanceOf(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOf
13+
abstract member-signature method _simpleInstanceOfTrue(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfTrue
14+
abstract member-signature method _simpleInstanceOfFalse(dynamic type) → core::bool*; -> core::Object::_simpleInstanceOfFalse
15+
abstract member-signature operator ==(dynamic other) → core::bool*; -> core::Object::==
16+
abstract member-signature get hashCode() → core::int*; -> core::Object::hashCode
17+
abstract member-signature method toString() → core::String*; -> core::Object::toString
18+
abstract member-signature method noSuchMethod(core::Invocation* invocation) → dynamic; -> core::Object::noSuchMethod
19+
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
20+
}
21+
static method expectThrows(() →* void f) → dynamic {
22+
try {
23+
f(){() →* void};
24+
}
25+
on dynamic catch(final dynamic e) {
26+
return;
27+
}
28+
throw "Expected an exception to be thrown!";
29+
}
30+
static method main() → dynamic {
31+
self::A<core::num*>* a = new self::A::•<core::int*>();
32+
<Y extends core::num*>(Y*) →* void f = a.{self::A::f}{<generic-covariant-impl Y extends core::num*>(Y*) →* void};
33+
self::expectThrows(() → Null {
34+
f<core::double*>(3.14){(core::double*) →* void};
35+
});
36+
}

pkg/front_end/testcases/runtime_checks/covariant_generic_parameter_tear_off.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class C<T> {
1515
}
1616

1717
F<num> g1(C<num> c) {
18-
return c. /*@ checkReturn=(num*) ->* void*/ f1;
18+
return c.f1;
1919
}
2020

2121
void g2(C<int> c, Object x) {
@@ -24,7 +24,7 @@ void g2(C<int> c, Object x) {
2424
}
2525

2626
G<List<num>, num> g3(C<num> c) {
27-
return c. /*@ checkReturn=(List<num*>*) ->* num**/ f2;
27+
return c.f2;
2828
}
2929

3030
void test() {

pkg/front_end/testcases/runtime_checks/covariant_generic_parameter_tear_off.dart.weak.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class C<T extends core::Object* = dynamic> extends core::Object {
2323
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
2424
}
2525
static method g1(self::C<core::num*>* c) → (core::num*) →* void {
26-
return c.{self::C::f1}{(core::num*) →* void} as{TypeError,CovarianceCheck} (core::num*) →* void;
26+
return c.{self::C::f1}{(core::num*) →* void};
2727
}
2828
static method g2(self::C<core::int*>* c, core::Object* x) → void {
2929
(core::Object*) →* void f = self::g1(c) as (core::Object*) →* void;
3030
f(x){(core::Object*) →* void};
3131
}
3232
static method g3(self::C<core::num*>* c) → (core::List<core::num*>*) →* core::num* {
33-
return c.{self::C::f2}{(core::List<core::num*>*) →* core::num*} as{TypeError,CovarianceCheck} (core::List<core::num*>*) →* core::num*;
33+
return c.{self::C::f2}{(core::List<core::num*>*) →* core::num*};
3434
}
3535
static method test() → void {
3636
(core::num*) →* void x = self::g1(new self::C::•<core::int*>());

pkg/front_end/testcases/runtime_checks/covariant_generic_parameter_tear_off.dart.weak.transformed.expect

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ class C<T extends core::Object* = dynamic> extends core::Object {
2323
abstract member-signature get runtimeType() → core::Type*; -> core::Object::runtimeType
2424
}
2525
static method g1(self::C<core::num*>* c) → (core::num*) →* void {
26-
return c.{self::C::f1}{(core::num*) →* void} as{TypeError,CovarianceCheck} (core::num*) →* void;
26+
return c.{self::C::f1}{(core::num*) →* void};
2727
}
2828
static method g2(self::C<core::int*>* c, core::Object* x) → void {
2929
(core::Object*) →* void f = self::g1(c) as (core::Object*) →* void;
3030
f(x){(core::Object*) →* void};
3131
}
3232
static method g3(self::C<core::num*>* c) → (core::List<core::num*>*) →* core::num* {
33-
return c.{self::C::f2}{(core::List<core::num*>*) →* core::num*} as{TypeError,CovarianceCheck} (core::List<core::num*>*) →* core::num*;
33+
return c.{self::C::f2}{(core::List<core::num*>*) →* core::num*};
3434
}
3535
static method test() → void {
3636
(core::num*) →* void x = self::g1(new self::C::•<core::int*>());

0 commit comments

Comments
 (0)