Skip to content

Commit 67dd480

Browse files
author
John Messerly
committed
Add analysis option that will be used to fix #26583
There's follow up work that is needed for CLI and analysis_options [email protected], [email protected] Review URL: https://codereview.chromium.org/2054443002 .
1 parent 643e682 commit 67dd480

File tree

7 files changed

+105
-157
lines changed

7 files changed

+105
-157
lines changed

pkg/analyzer/lib/src/context/context.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
271271
((options is AnalysisOptionsImpl)
272272
? this._options.strongModeHints != options.strongModeHints
273273
: false) ||
274+
((options is AnalysisOptionsImpl)
275+
? this._options.implicitCasts != options.implicitCasts
276+
: false) ||
274277
this._options.enableStrictCallChecks !=
275278
options.enableStrictCallChecks ||
276279
this._options.enableGenericMethods != options.enableGenericMethods ||
@@ -301,6 +304,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
301304
this._options.trackCacheDependencies = options.trackCacheDependencies;
302305
if (options is AnalysisOptionsImpl) {
303306
this._options.strongModeHints = options.strongModeHints;
307+
this._options.implicitCasts = options.implicitCasts;
304308
}
305309
if (needsRecompute) {
306310
for (WorkManager workManager in workManagers) {

pkg/analyzer/lib/src/generated/engine.dart

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,14 @@ class AnalysisOptionsImpl implements AnalysisOptions {
12941294
@override
12951295
bool trackCacheDependencies = true;
12961296

1297+
/**
1298+
* A flag indicating whether implicit casts are allowed in [strongMode]
1299+
* (they are always allowed in Dart 1.0 mode).
1300+
*
1301+
* This option is experimental and subject to change.
1302+
*/
1303+
bool implicitCasts = true;
1304+
12971305
/**
12981306
* Initialize a newly created set of analysis options to have their default
12991307
* values.
@@ -1325,6 +1333,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
13251333
strongMode = options.strongMode;
13261334
if (options is AnalysisOptionsImpl) {
13271335
strongModeHints = options.strongModeHints;
1336+
implicitCasts = options.implicitCasts;
13281337
}
13291338
trackCacheDependencies = options.trackCacheDependencies;
13301339
}

pkg/analyzer/lib/src/task/dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5684,7 +5684,7 @@ class StrongModeVerifyUnitTask extends SourceBasedAnalysisTask {
56845684
if (options.strongMode) {
56855685
unit.accept(new CodeChecker(
56865686
typeProvider, new StrongTypeSystemImpl(), errorListener,
5687-
hints: options.strongModeHints));
5687+
options));
56885688
}
56895689
//
56905690
// Record outputs.

pkg/analyzer/lib/src/task/strong/checker.dart

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
1313
import 'package:analyzer/dart/element/element.dart';
1414
import 'package:analyzer/dart/element/type.dart';
1515
import 'package:analyzer/src/dart/element/type.dart';
16+
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
1617
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
1718
import 'package:analyzer/src/generated/type_system.dart';
1819

@@ -101,16 +102,15 @@ class CodeChecker extends RecursiveAstVisitor {
101102
final TypeProvider typeProvider;
102103
final AnalysisErrorListener reporter;
103104
final _OverrideChecker _overrideChecker;
104-
final bool _hints;
105+
final AnalysisOptionsImpl _options;
105106

106107
bool _failure = false;
108+
107109
CodeChecker(TypeProvider typeProvider, StrongTypeSystemImpl rules,
108-
AnalysisErrorListener reporter,
109-
{bool hints: false})
110+
AnalysisErrorListener reporter, this._options)
110111
: typeProvider = typeProvider,
111112
rules = rules,
112113
reporter = reporter,
113-
_hints = hints,
114114
_overrideChecker = new _OverrideChecker(typeProvider, rules, reporter);
115115

116116
bool get failure => _failure || _overrideChecker._failure;
@@ -346,7 +346,7 @@ class CodeChecker extends RecursiveAstVisitor {
346346

347347
if (rules.isSubtypeOf(sequenceType, iterableType)) {
348348
_recordMessage(DownCast.create(
349-
rules, node.iterable, iterableType, sequenceType));
349+
rules, node.iterable, iterableType, sequenceType, _options));
350350
elementType = DynamicTypeImpl.instance;
351351
}
352352
}
@@ -632,11 +632,11 @@ class CodeChecker extends RecursiveAstVisitor {
632632
rules.isSubtypeOf(lhsType, rhsType)) {
633633
// This is also slightly different from spec, but allows us to keep
634634
// compound operators in the int += num and num += dynamic cases.
635-
staticInfo =
636-
DownCast.create(rules, expr.rightHandSide, rhsType, lhsType);
635+
staticInfo = DownCast.create(
636+
rules, expr.rightHandSide, rhsType, lhsType, _options);
637637
rhsType = lhsType;
638638
} else {
639-
staticInfo = new StaticTypeError(rules, expr, lhsType);
639+
staticInfo = new StaticTypeError(expr, lhsType);
640640
}
641641
_recordMessage(staticInfo);
642642
}
@@ -679,7 +679,7 @@ class CodeChecker extends RecursiveAstVisitor {
679679

680680
// Downcast if toT <: fromT
681681
if (rules.isSubtypeOf(to, from)) {
682-
_recordMessage(DownCast.create(rules, expr, from, to));
682+
_recordMessage(DownCast.create(rules, expr, from, to, _options));
683683
return;
684684
}
685685

@@ -694,7 +694,7 @@ class CodeChecker extends RecursiveAstVisitor {
694694
// Iterable<T> for some concrete T (e.g. Object). These are unrelated
695695
// in the restricted system, but List<dynamic> <: Iterable<T> in dart.
696696
if (from.isAssignableTo(to)) {
697-
_recordMessage(DownCast.create(rules, expr, from, to));
697+
_recordMessage(DownCast.create(rules, expr, from, to, _options));
698698
}
699699
}
700700

@@ -894,8 +894,8 @@ class CodeChecker extends RecursiveAstVisitor {
894894
}
895895

896896
void _recordDynamicInvoke(AstNode node, AstNode target) {
897-
if (_hints) {
898-
reporter.onError(new DynamicInvoke(rules, node).toAnalysisError());
897+
if (_options.strongModeHints) {
898+
reporter.onError(new DynamicInvoke(node).toAnalysisError());
899899
}
900900
// TODO(jmesserly): we may eventually want to record if the whole operation
901901
// (node) was dynamic, rather than the target, but this is an easier fit
@@ -908,7 +908,7 @@ class CodeChecker extends RecursiveAstVisitor {
908908
var error = info.toAnalysisError();
909909
var severity = error.errorCode.errorSeverity;
910910
if (severity == ErrorSeverity.ERROR) _failure = true;
911-
if (severity != ErrorSeverity.INFO || _hints) {
911+
if (severity != ErrorSeverity.INFO || _options.strongModeHints) {
912912
reporter.onError(error);
913913
}
914914

0 commit comments

Comments
 (0)