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

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

Issue 2976963002: Add --no-declaration-casts option to analyzer. (Closed)
Patch Set: Fix comment Created 3 years, 5 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/lib/src/task/dart.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 8507bf368cfbd86dbd030a9cab1634db56b936ea..1ed098dd935d46568487bf3b8e8d3eba1d188225 100644
--- a/pkg/analyzer/lib/src/generated/type_system.dart
+++ b/pkg/analyzer/lib/src/generated/type_system.dart
@@ -48,6 +48,13 @@ class StrongTypeSystemImpl extends TypeSystem {
static bool _comparingTypeParameterBounds = false;
/**
+ * True if declaration casts should be allowed, otherwise false.
+ *
+ * This affects the behavior of [isAssignableTo].
+ */
+ final bool declarationCasts;
+
+ /**
* True if implicit casts should be allowed, otherwise false.
*
* This affects the behavior of [isAssignableTo].
@@ -62,7 +69,8 @@ class StrongTypeSystemImpl extends TypeSystem {
final TypeProvider typeProvider;
StrongTypeSystemImpl(this.typeProvider,
- {this.implicitCasts: true,
+ {this.declarationCasts: true,
+ this.implicitCasts: true,
this.nonnullableTypes: AnalysisOptionsImpl.NONNULLABLE_TYPES});
@override
@@ -409,7 +417,8 @@ class StrongTypeSystemImpl extends TypeSystem {
}
@override
- bool isAssignableTo(DartType fromType, DartType toType) {
+ bool isAssignableTo(DartType fromType, DartType toType,
+ {bool isDeclarationCast = false}) {
// TODO(leafp): Document the rules in play here
// An actual subtype
@@ -417,7 +426,11 @@ class StrongTypeSystemImpl extends TypeSystem {
return true;
}
- if (!implicitCasts) {
+ if (isDeclarationCast) {
+ if (!declarationCasts) {
+ return false;
+ }
+ } else if (!implicitCasts) {
return false;
}
@@ -1222,7 +1235,8 @@ abstract class TypeSystem {
* Return `true` if the [leftType] is assignable to the [rightType] (that is,
* if leftType <==> rightType).
*/
- bool isAssignableTo(DartType leftType, DartType rightType);
+ bool isAssignableTo(DartType leftType, DartType rightType,
+ {bool isDeclarationCast = false});
/**
* Return `true` if the [leftType] is more specific than the [rightType]
@@ -1476,6 +1490,7 @@ abstract class TypeSystem {
var options = context.analysisOptions as AnalysisOptionsImpl;
return options.strongMode
? new StrongTypeSystemImpl(context.typeProvider,
+ declarationCasts: options.declarationCasts,
implicitCasts: options.implicitCasts,
nonnullableTypes: options.nonnullableTypes)
: new TypeSystemImpl(context.typeProvider);
@@ -1511,7 +1526,8 @@ class TypeSystemImpl extends TypeSystem {
}
@override
- bool isAssignableTo(DartType leftType, DartType rightType) {
+ bool isAssignableTo(DartType leftType, DartType rightType,
+ {bool isDeclarationCast = false}) {
return leftType.isAssignableTo(rightType);
}
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | pkg/analyzer/lib/src/task/dart.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698