Don't assert that T2 and T3 are num subtypes.
Bug: https://buganizer.corp.google.com/issues/179461891
Change-Id: I87be38a09aade855413382b1d86476c295c4e317
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/183300
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
diff --git a/pkg/analyzer/lib/src/dart/element/type_system.dart b/pkg/analyzer/lib/src/dart/element/type_system.dart
index b79502d..3fa2aa1 100644
--- a/pkg/analyzer/lib/src/dart/element/type_system.dart
+++ b/pkg/analyzer/lib/src/dart/element/type_system.dart
@@ -1795,8 +1795,6 @@
var numTypeQuestion = typeProvider.numTypeQuestion;
if (isSubtypeOf(t1, numTypeQuestion) && !t2.isBottom && !t3.isBottom) {
assert(!t1.isBottom);
- assert(isSubtypeOf(t2, numTypeQuestion));
- assert(isSubtypeOf(t3, numTypeQuestion));
// Then:
// - If T1, T2 and T3 are all subtypes of int, the static type of e is
// int.
diff --git a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
index 9393416..e493bde8 100644
--- a/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
+++ b/pkg/analyzer/test/src/dart/resolution/method_invocation_test.dart
@@ -189,6 +189,21 @@
expectedType: 'num');
}
+ test_clamp_int_double_dynamic() async {
+ await assertNoErrorsInCode('''
+f(int a, double b, dynamic c) {
+ a.clamp(b, c);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('clamp'),
+ elementMatcher(numElement.getMethod('clamp'),
+ isLegacy: isNullSafetySdkAndLegacyLibrary),
+ 'num Function(num, num)',
+ expectedType: 'num');
+ }
+
test_clamp_int_double_int() async {
await assertNoErrorsInCode('''
f(int a, double b, int c) {
@@ -204,6 +219,36 @@
expectedType: 'num');
}
+ test_clamp_int_dynamic_double() async {
+ await assertNoErrorsInCode('''
+f(int a, dynamic b, double c) {
+ a.clamp(b, c);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('clamp'),
+ elementMatcher(numElement.getMethod('clamp'),
+ isLegacy: isNullSafetySdkAndLegacyLibrary),
+ 'num Function(num, num)',
+ expectedType: 'num');
+ }
+
+ test_clamp_int_dynamic_int() async {
+ await assertNoErrorsInCode('''
+f(int a, dynamic b, int c) {
+ a.clamp(b, c);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('clamp'),
+ elementMatcher(numElement.getMethod('clamp'),
+ isLegacy: isNullSafetySdkAndLegacyLibrary),
+ 'num Function(num, num)',
+ expectedType: 'num');
+ }
+
test_clamp_int_int_double() async {
await assertNoErrorsInCode('''
f(int a, int b, double c) {
@@ -219,6 +264,21 @@
expectedType: 'num');
}
+ test_clamp_int_int_dynamic() async {
+ await assertNoErrorsInCode('''
+f(int a, int b, dynamic c) {
+ a.clamp(b, c);
+}
+''');
+
+ assertMethodInvocation(
+ findNode.methodInvocation('clamp'),
+ elementMatcher(numElement.getMethod('clamp'),
+ isLegacy: isNullSafetySdkAndLegacyLibrary),
+ 'num Function(num, num)',
+ expectedType: 'num');
+ }
+
test_clamp_int_int_int() async {
await assertNoErrorsInCode('''
f(int a, int b, int c) {