Hide inference hints. Fixes #24563.

BUG=
R=jmesserly@google.com

Review URL: https://codereview.chromium.org/1498573002 .
This commit is contained in:
Leaf Petersen
2015-12-02 13:07:46 -08:00
parent c030056158
commit daf5f6d258
5 changed files with 73 additions and 24 deletions
@@ -267,6 +267,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
(this._options.lint && !options.lint) ||
this._options.preserveComments != options.preserveComments ||
this._options.strongMode != options.strongMode ||
((options is AnalysisOptionsImpl)
? this._options.strongModeHints != options.strongModeHints
: false) ||
this._options.enableStrictCallChecks !=
options.enableStrictCallChecks ||
this._options.enableGenericMethods != options.enableGenericMethods ||
@@ -290,6 +293,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.lint = options.lint;
this._options.preserveComments = options.preserveComments;
this._options.strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
this._options.strongModeHints = options.strongModeHints;
}
if (needsRecompute) {
for (WorkManager workManager in workManagers) {
workManager.onAnalysisOptionsChanged();
@@ -1170,6 +1170,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
(this._options.hint && !options.hint) ||
this._options.preserveComments != options.preserveComments ||
this._options.strongMode != options.strongMode ||
((options is AnalysisOptionsImpl)
? this._options.strongModeHints != options.strongModeHints
: false) ||
this._options.enableStrictCallChecks !=
options.enableStrictCallChecks ||
this._options.enableSuperMixins != options.enableSuperMixins;
@@ -1206,6 +1209,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
this._options.lint = options.lint;
this._options.preserveComments = options.preserveComments;
this._options.strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
this._options.strongModeHints = options.strongModeHints;
}
_generateImplicitErrors = options.generateImplicitErrors;
_generateSdkErrors = options.generateSdkErrors;
if (needsRecompute) {
@@ -6461,6 +6467,14 @@ class AnalysisOptionsImpl implements AnalysisOptions {
*/
bool strongMode = false;
/**
* A flag indicating whether strong-mode inference hints should be
* used. This flag is not exposed in the interface, and should be
* replaced by something more general.
*/
// TODO(leafp): replace this with something more general
bool strongModeHints = false;
/**
* Initialize a newly created set of analysis options to have their default
* values.
@@ -6488,6 +6502,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
lint = options.lint;
preserveComments = options.preserveComments;
strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
strongModeHints = options.strongModeHints;
}
}
/**
@@ -6510,6 +6527,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
lint = options.lint;
preserveComments = options.preserveComments;
strongMode = options.strongMode;
if (options is AnalysisOptionsImpl) {
strongModeHints = options.strongModeHints;
}
}
bool get analyzeFunctionBodies {
+15 -5
View File
@@ -5771,6 +5771,11 @@ class InferenceContext {
*/
final AnalysisErrorListener _errorListener;
/**
* If true, emit hints when types are inferred
*/
final bool _inferenceHints;
/**
* Type provider, needed for type matching.
*/
@@ -5792,8 +5797,8 @@ class InferenceContext {
*/
List<DartType> _returnStack = <DartType>[];
InferenceContext._(
this._errorListener, TypeProvider typeProvider, this._typeSystem)
InferenceContext._(this._errorListener, TypeProvider typeProvider,
this._typeSystem, this._inferenceHints)
: _typeProvider = typeProvider,
_rules = new TypeRules(typeProvider);
@@ -5837,7 +5842,7 @@ class InferenceContext {
*/
void recordInference(Expression node, DartType type) {
StaticInfo info = InferredType.create(_rules, node, type);
if (info == null) {
if (!_inferenceHints || info == null) {
return;
}
AnalysisError error = info.toAnalysisError();
@@ -10695,8 +10700,13 @@ class ResolverVisitor extends ScopedVisitor {
}
this.elementResolver = new ElementResolver(this);
this.typeSystem = definingLibrary.context.typeSystem;
this.inferenceContext =
new InferenceContext._(errorListener, typeProvider, typeSystem);
bool strongModeHints = false;
AnalysisOptions options = definingLibrary.context.analysisOptions;
if (options is AnalysisOptionsImpl) {
strongModeHints = options.strongModeHints;
}
this.inferenceContext = new InferenceContext._(
errorListener, typeProvider, typeSystem, strongModeHints);
if (typeAnalyzerFactory == null) {
this.typeAnalyzer = new StaticTypeAnalyzer(this);
} else {
+31 -19
View File
@@ -12587,6 +12587,18 @@ class StrongModeDownwardsInferenceTest extends ResolverTestCase {
expect(functionReturnValue(4).staticType, typeProvider.stringType);
}
void test_inference_hints() {
Source source = addSource(r'''
void main () {
var x = 3;
List<int> l0 = [];
}
''');
LibraryElement library = resolve2(source);
assertNoErrors(source);
verify([source]);
}
void test_instanceCreation() {
String code = r'''
class A<S, T> {
@@ -13819,25 +13831,6 @@ class TypeOverrideManagerTest extends EngineTestCase {
@reflectiveTest
class TypePropagationTest extends ResolverTestCase {
void test_invocation_target_prefixed() {
addNamedSource(
'/helper.dart',
'''
library helper;
int max(int x, int y) => 0;
''');
String code = '''
import 'helper.dart' as helper;
main() {
helper.max(10, 10); // marker
}''';
SimpleIdentifier methodName =
_findMarkedIdentifier(code, "(10, 10); // marker");
MethodInvocation methodInvoke = methodName.parent;
expect(methodInvoke.methodName.staticElement, isNotNull);
expect(methodInvoke.methodName.propagatedElement, isNull);
}
void fail_mergePropagatedTypesAtJoinPoint_1() {
// https://code.google.com/p/dart/issues/detail?id=19929
_assertTypeOfMarkedExpression(
@@ -14657,6 +14650,25 @@ main() {
}
}
void test_invocation_target_prefixed() {
addNamedSource(
'/helper.dart',
'''
library helper;
int max(int x, int y) => 0;
''');
String code = '''
import 'helper.dart' as helper;
main() {
helper.max(10, 10); // marker
}''';
SimpleIdentifier methodName =
_findMarkedIdentifier(code, "(10, 10); // marker");
MethodInvocation methodInvoke = methodName.parent;
expect(methodInvoke.methodName.staticElement, isNotNull);
expect(methodInvoke.methodName.propagatedElement, isNull);
}
void test_is_conditional() {
Source source = addSource(r'''
class A {}
@@ -63,6 +63,7 @@ void testChecker(String name, Map<String, String> testFiles) {
AnalysisEngine.instance.useTaskModel = true;
var context = AnalysisEngine.instance.createAnalysisContext();
context.analysisOptions.strongMode = true;
context.analysisOptions.strongModeHints = true;
context.sourceFactory = new SourceFactory([
new MockDartSdk(mockSdkSources, reportMissing: true).resolver,