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

Unified Diff: pkg/analyzer/lib/src/generated/type_system.dart

Issue 1585323003: fix #25486, promote from dynamic in strong mode (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/type_system.dart
diff --git a/pkg/analyzer/lib/src/generated/type_system.dart b/pkg/analyzer/lib/src/generated/type_system.dart
index 911dfa9f81e072ddd26c99fbd157abb18979fa3a..5eb00ee385d3c67024d4c5f5bd9afdc82ecf54d9 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -29,6 +29,9 @@ class StrongTypeSystemImpl implements TypeSystem {
return ft.parameters.any((p) => predicate(p.type));
}
+ @override
+ bool canPromoteToType(DartType to, DartType from) => isSubtypeOf(to, from);
+
/**
* Given a type t, if t is an interface type with a call method
* defined, return the function type for the call method, otherwise
@@ -563,6 +566,16 @@ class StrongTypeSystemImpl implements TypeSystem {
*/
abstract class TypeSystem {
/**
+ * Returns `true` if we can promote to the first type from the second type.
+ *
+ * In the standard Dart type system, it is not possible to promote from or to
+ * `dynamic`, and we must be promoting to a more specific type.
+ *
+ * In strong mode, this is equivalent to [isSubtypeOf].
+ */
+ bool canPromoteToType(DartType to, DartType from);
+
+ /**
* Compute the least upper bound of two types.
*/
DartType getLeastUpperBound(
@@ -606,6 +619,14 @@ class TypeSystemImpl implements TypeSystem {
TypeSystemImpl();
@override
+ bool canPromoteToType(DartType to, DartType from) {
+ // Declared type should not be "dynamic".
+ // Promoted type should not be "dynamic".
+ // Promoted type should be more specific than declared.
+ return !from.isDynamic && !to.isDynamic && to.isMoreSpecificThan(from);
+ }
+
+ @override
DartType getLeastUpperBound(
TypeProvider typeProvider, DartType type1, DartType type2) {
// The least upper bound relation is reflexive.
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/test/generated/resolver_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698