Skip to content

Commit

Permalink
Add analysis option that will be used to fix #26583
Browse files Browse the repository at this point in the history
There's follow up work that is needed for CLI and analysis_options

R=brianwilkerson@google.com, leafp@google.com

Review URL: https://codereview.chromium.org/2054443002 .
  • Loading branch information
John Messerly committed Jun 10, 2016
1 parent 643e682 commit 67dd480
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 157 deletions.
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/src/context/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
((options is AnalysisOptionsImpl)
? this._options.strongModeHints != options.strongModeHints
: false) ||
((options is AnalysisOptionsImpl)
? this._options.implicitCasts != options.implicitCasts
: false) ||
this._options.enableStrictCallChecks !=
options.enableStrictCallChecks ||
this._options.enableGenericMethods != options.enableGenericMethods ||
Expand Down Expand Up @@ -301,6 +304,7 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.trackCacheDependencies = options.trackCacheDependencies;
if (options is AnalysisOptionsImpl) {
this._options.strongModeHints = options.strongModeHints;
this._options.implicitCasts = options.implicitCasts;
}
if (needsRecompute) {
for (WorkManager workManager in workManagers) {
Expand Down
9 changes: 9 additions & 0 deletions pkg/analyzer/lib/src/generated/engine.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1294,6 +1294,14 @@ class AnalysisOptionsImpl implements AnalysisOptions {
@override
bool trackCacheDependencies = true;

/**
* A flag indicating whether implicit casts are allowed in [strongMode]
* (they are always allowed in Dart 1.0 mode).
*
* This option is experimental and subject to change.
*/
bool implicitCasts = true;

/**
* Initialize a newly created set of analysis options to have their default
* values.
Expand Down Expand Up @@ -1325,6 +1333,7 @@ class AnalysisOptionsImpl implements AnalysisOptions {
strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
strongModeHints = options.strongModeHints;
implicitCasts = options.implicitCasts;
}
trackCacheDependencies = options.trackCacheDependencies;
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/lib/src/task/dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5684,7 +5684,7 @@ class StrongModeVerifyUnitTask extends SourceBasedAnalysisTask {
if (options.strongMode) {
unit.accept(new CodeChecker(
typeProvider, new StrongTypeSystemImpl(), errorListener,
hints: options.strongModeHints));
options));
}
//
// Record outputs.
Expand Down
26 changes: 13 additions & 13 deletions pkg/analyzer/lib/src/task/strong/checker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/generated/engine.dart' show AnalysisOptionsImpl;
import 'package:analyzer/src/generated/resolver.dart' show TypeProvider;
import 'package:analyzer/src/generated/type_system.dart';

Expand Down Expand Up @@ -101,16 +102,15 @@ class CodeChecker extends RecursiveAstVisitor {
final TypeProvider typeProvider;
final AnalysisErrorListener reporter;
final _OverrideChecker _overrideChecker;
final bool _hints;
final AnalysisOptionsImpl _options;

bool _failure = false;

CodeChecker(TypeProvider typeProvider, StrongTypeSystemImpl rules,
AnalysisErrorListener reporter,
{bool hints: false})
AnalysisErrorListener reporter, this._options)
: typeProvider = typeProvider,
rules = rules,
reporter = reporter,
_hints = hints,
_overrideChecker = new _OverrideChecker(typeProvider, rules, reporter);

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

if (rules.isSubtypeOf(sequenceType, iterableType)) {
_recordMessage(DownCast.create(
rules, node.iterable, iterableType, sequenceType));
rules, node.iterable, iterableType, sequenceType, _options));
elementType = DynamicTypeImpl.instance;
}
}
Expand Down Expand Up @@ -632,11 +632,11 @@ class CodeChecker extends RecursiveAstVisitor {
rules.isSubtypeOf(lhsType, rhsType)) {
// This is also slightly different from spec, but allows us to keep
// compound operators in the int += num and num += dynamic cases.
staticInfo =
DownCast.create(rules, expr.rightHandSide, rhsType, lhsType);
staticInfo = DownCast.create(
rules, expr.rightHandSide, rhsType, lhsType, _options);
rhsType = lhsType;
} else {
staticInfo = new StaticTypeError(rules, expr, lhsType);
staticInfo = new StaticTypeError(expr, lhsType);
}
_recordMessage(staticInfo);
}
Expand Down Expand Up @@ -679,7 +679,7 @@ class CodeChecker extends RecursiveAstVisitor {

// Downcast if toT <: fromT
if (rules.isSubtypeOf(to, from)) {
_recordMessage(DownCast.create(rules, expr, from, to));
_recordMessage(DownCast.create(rules, expr, from, to, _options));
return;
}

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

Expand Down Expand Up @@ -894,8 +894,8 @@ class CodeChecker extends RecursiveAstVisitor {
}

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

Expand Down
Loading

0 comments on commit 67dd480

Please sign in to comment.