-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[dart2js] Clean up nullability adjustments in interface sufficiency test
Now that #60076 has been addressed, we no longer need to widen the nullability ourselves. Change-Id: I4bc5a1767d9e2d98bcf0ca4c24171482e0f600ac Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/409162 Commit-Queue: Mayank Patke <fishythefish@google.com> Reviewed-by: Stephen Adams <sra@google.com>
- Loading branch information
1 parent
23cac7c
commit 66fa0e2
Showing
2 changed files
with
106 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
pkg/compiler/test/codegen/data/is_test_weakening_with_bounds.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
// `is` tests against some parameterized interface types are equivalent to a | ||
// weaker test for just the interace. The weaker test is usually more efficient, | ||
// sometimes being compiled to `instanceof`. | ||
|
||
class Base<T extends num> { | ||
/*member: Base.test1:function(other) { | ||
if (other instanceof A.D1) | ||
return other.foo$0(); | ||
return "other"; | ||
}*/ | ||
@pragma('dart2js:parameter:trust') | ||
String test1(Base<T> other) { | ||
if (other is D1<T>) return other.foo(); | ||
return 'other'; | ||
} | ||
|
||
/*member: Base.test1qn:function(other) { | ||
if (other instanceof A.D1) | ||
return other.foo$0(); | ||
return "other"; | ||
}*/ | ||
@pragma('dart2js:parameter:trust') | ||
String test1qn(Base<T>? other) { | ||
if (other is D1<T>) return other.foo(); | ||
return 'other'; | ||
} | ||
|
||
/*member: Base.test1nq:function(other) { | ||
if (other instanceof A.D1) | ||
return other.method$0(); | ||
return "other"; | ||
}*/ | ||
@pragma('dart2js:parameter:trust') | ||
String? test1nq(Base<T> other) { | ||
if (other is D1<T>?) return other.method(); // No promotion, so can't foo(). | ||
return 'other'; | ||
} | ||
|
||
/*member: Base.test1qq:function(other) { | ||
var t1; | ||
if (type$.nullable_D1_dynamic._is(other)) { | ||
t1 = other.foo$0(); | ||
return t1; | ||
} | ||
return "other"; | ||
}*/ | ||
@pragma('dart2js:parameter:trust') | ||
String? test1qq(Base<T>? other) { | ||
if (other is D1<T>?) return other?.foo(); | ||
return 'other'; | ||
} | ||
|
||
/*member: Base.test2:function(other) { | ||
if (other instanceof A.D2) | ||
return other.bar$0(); | ||
return "other"; | ||
}*/ | ||
@pragma('dart2js:parameter:trust') | ||
String test2(Base<T> other) { | ||
if (other is D2<T>) return other.bar(); | ||
return 'other'; | ||
} | ||
|
||
@pragma('dart2js:never-inline') | ||
/*member: Base.method:ignore*/ | ||
String method() => 'Base.method'; | ||
} | ||
|
||
class D1<T extends num> extends Base<T> { | ||
@pragma('dart2js:never-inline') | ||
/*member: D1.foo:ignore*/ | ||
String foo() => 'D1<$T>.foo'; | ||
} | ||
|
||
class D2<T extends num> extends D1<T> { | ||
@pragma('dart2js:never-inline') | ||
/*member: D2.bar:ignore*/ | ||
String bar() => 'D2.bar'; | ||
} | ||
|
||
/*member: main:ignore*/ | ||
main() { | ||
final items = [Base<int>(), D1<int>(), D2<int>()]; | ||
|
||
for (final item in items) { | ||
print(item.test1(items.first)); | ||
print(item.test1(item)); | ||
|
||
print(item.test1qn(items.first)); | ||
print(item.test1qn(item)); | ||
print(item.test1nq(items.first)); | ||
print(item.test1nq(item)); | ||
print(item.test1qq(items.first)); | ||
print(item.test1qq(item)); | ||
|
||
print(item.test2(items.first)); | ||
print(item.test2(item)); | ||
} | ||
} |