Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(206)

Unified Diff: pkg/front_end/testcases/inference/generic_methods_dart_math_min_max.dart

Issue 2846103002: Generated front_end/testcases/inference test files from Analyzer tests. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: pkg/front_end/testcases/inference/generic_methods_dart_math_min_max.dart
diff --git a/pkg/front_end/testcases/inference/generic_methods_dart_math_min_max.dart b/pkg/front_end/testcases/inference/generic_methods_dart_math_min_max.dart
new file mode 100644
index 0000000000000000000000000000000000000000..63f7e521eeff74693034bde5dcc71029ec6eb990
--- /dev/null
+++ b/pkg/front_end/testcases/inference/generic_methods_dart_math_min_max.dart
@@ -0,0 +1,36 @@
+// Copyright (c) 2017, 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.
+
+/*@testedFeatures=inference*/
+library test;
+
+import 'dart:math';
+
+void printInt(int x) => print(x);
+void printDouble(double x) => print(x);
+
+num myMax(num x, num y) => max(x, y);
+
+main() {
+ // Okay if static types match.
+ printInt(max(1, 2));
+ printInt(min(1, 2));
+ printDouble(max(1.0, 2.0));
+ printDouble(min(1.0, 2.0));
+
+ // No help for user-defined functions from num->num->num.
+ printInt(/*info:DOWN_CAST_IMPLICIT*/ myMax(1, 2));
+ printInt(myMax(1, 2) as int);
+
+ // Mixing int and double means return type is num.
+ printInt(max(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0));
+ printInt(min(1, /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 2.0));
+ printDouble(max(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0));
+ printDouble(min(/*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ 1, 2.0));
+
+ // Types other than int and double are not accepted.
+ printInt(min(
+ /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "hi",
+ /*error:ARGUMENT_TYPE_NOT_ASSIGNABLE*/ "there"));
+}

Powered by Google App Engine
This is Rietveld 408576698