Skip to content

Commit daf5f6d

Browse files
committed
Hide inference hints. Fixes #24563.
BUG= [email protected] Review URL: https://codereview.chromium.org/1498573002 .
1 parent c030056 commit daf5f6d

File tree

5 files changed

+73
-24
lines changed

5 files changed

+73
-24
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
267267
(this._options.lint && !options.lint) ||
268268
this._options.preserveComments != options.preserveComments ||
269269
this._options.strongMode != options.strongMode ||
270+
((options is AnalysisOptionsImpl)
271+
? this._options.strongModeHints != options.strongModeHints
272+
: false) ||
270273
this._options.enableStrictCallChecks !=
271274
options.enableStrictCallChecks ||
272275
this._options.enableGenericMethods != options.enableGenericMethods ||
@@ -290,6 +293,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
290293
this._options.lint = options.lint;
291294
this._options.preserveComments = options.preserveComments;
292295
this._options.strongMode = options.strongMode;
296+
if (options is AnalysisOptionsImpl) {
297+
this._options.strongModeHints = options.strongModeHints;
298+
}
293299
if (needsRecompute) {
294300
for (WorkManager workManager in workManagers) {
295301
workManager.onAnalysisOptionsChanged();

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
11701170
(this._options.hint && !options.hint) ||
11711171
this._options.preserveComments != options.preserveComments ||
11721172
this._options.strongMode != options.strongMode ||
1173+
((options is AnalysisOptionsImpl)
1174+
? this._options.strongModeHints != options.strongModeHints
1175+
: false) ||
11731176
this._options.enableStrictCallChecks !=
11741177
options.enableStrictCallChecks ||
11751178
this._options.enableSuperMixins != options.enableSuperMixins;
@@ -1206,6 +1209,9 @@ class AnalysisContextImpl implements InternalAnalysisContext {
12061209
this._options.lint = options.lint;
12071210
this._options.preserveComments = options.preserveComments;
12081211
this._options.strongMode = options.strongMode;
1212+
if (options is AnalysisOptionsImpl) {
1213+
this._options.strongModeHints = options.strongModeHints;
1214+
}
12091215
_generateImplicitErrors = options.generateImplicitErrors;
12101216
_generateSdkErrors = options.generateSdkErrors;
12111217
if (needsRecompute) {
@@ -6461,6 +6467,14 @@ class AnalysisOptionsImpl implements AnalysisOptions {
64616467
*/
64626468
bool strongMode = false;
64636469

6470+
/**
6471+
* A flag indicating whether strong-mode inference hints should be
6472+
* used. This flag is not exposed in the interface, and should be
6473+
* replaced by something more general.
6474+
*/
6475+
// TODO(leafp): replace this with something more general
6476+
bool strongModeHints = false;
6477+
64646478
/**
64656479
* Initialize a newly created set of analysis options to have their default
64666480
* values.
@@ -6488,6 +6502,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
64886502
lint = options.lint;
64896503
preserveComments = options.preserveComments;
64906504
strongMode = options.strongMode;
6505+
if (options is AnalysisOptionsImpl) {
6506+
strongModeHints = options.strongModeHints;
6507+
}
64916508
}
64926509

64936510
/**
@@ -6510,6 +6527,9 @@ class AnalysisOptionsImpl implements AnalysisOptions {
65106527
lint = options.lint;
65116528
preserveComments = options.preserveComments;
65126529
strongMode = options.strongMode;
6530+
if (options is AnalysisOptionsImpl) {
6531+
strongModeHints = options.strongModeHints;
6532+
}
65136533
}
65146534

65156535
bool get analyzeFunctionBodies {

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

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5771,6 +5771,11 @@ class InferenceContext {
57715771
*/
57725772
final AnalysisErrorListener _errorListener;
57735773

5774+
/**
5775+
* If true, emit hints when types are inferred
5776+
*/
5777+
final bool _inferenceHints;
5778+
57745779
/**
57755780
* Type provider, needed for type matching.
57765781
*/
@@ -5792,8 +5797,8 @@ class InferenceContext {
57925797
*/
57935798
List<DartType> _returnStack = <DartType>[];
57945799

5795-
InferenceContext._(
5796-
this._errorListener, TypeProvider typeProvider, this._typeSystem)
5800+
InferenceContext._(this._errorListener, TypeProvider typeProvider,
5801+
this._typeSystem, this._inferenceHints)
57975802
: _typeProvider = typeProvider,
57985803
_rules = new TypeRules(typeProvider);
57995804

@@ -5837,7 +5842,7 @@ class InferenceContext {
58375842
*/
58385843
void recordInference(Expression node, DartType type) {
58395844
StaticInfo info = InferredType.create(_rules, node, type);
5840-
if (info == null) {
5845+
if (!_inferenceHints || info == null) {
58415846
return;
58425847
}
58435848
AnalysisError error = info.toAnalysisError();
@@ -10695,8 +10700,13 @@ class ResolverVisitor extends ScopedVisitor {
1069510700
}
1069610701
this.elementResolver = new ElementResolver(this);
1069710702
this.typeSystem = definingLibrary.context.typeSystem;
10698-
this.inferenceContext =
10699-
new InferenceContext._(errorListener, typeProvider, typeSystem);
10703+
bool strongModeHints = false;
10704+
AnalysisOptions options = definingLibrary.context.analysisOptions;
10705+
if (options is AnalysisOptionsImpl) {
10706+
strongModeHints = options.strongModeHints;
10707+
}
10708+
this.inferenceContext = new InferenceContext._(
10709+
errorListener, typeProvider, typeSystem, strongModeHints);
1070010710
if (typeAnalyzerFactory == null) {
1070110711
this.typeAnalyzer = new StaticTypeAnalyzer(this);
1070210712
} else {

pkg/analyzer/test/generated/resolver_test.dart

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12587,6 +12587,18 @@ class StrongModeDownwardsInferenceTest extends ResolverTestCase {
1258712587
expect(functionReturnValue(4).staticType, typeProvider.stringType);
1258812588
}
1258912589

12590+
void test_inference_hints() {
12591+
Source source = addSource(r'''
12592+
void main () {
12593+
var x = 3;
12594+
List<int> l0 = [];
12595+
}
12596+
''');
12597+
LibraryElement library = resolve2(source);
12598+
assertNoErrors(source);
12599+
verify([source]);
12600+
}
12601+
1259012602
void test_instanceCreation() {
1259112603
String code = r'''
1259212604
class A<S, T> {
@@ -13819,25 +13831,6 @@ class TypeOverrideManagerTest extends EngineTestCase {
1381913831

1382013832
@reflectiveTest
1382113833
class TypePropagationTest extends ResolverTestCase {
13822-
void test_invocation_target_prefixed() {
13823-
addNamedSource(
13824-
'/helper.dart',
13825-
'''
13826-
library helper;
13827-
int max(int x, int y) => 0;
13828-
''');
13829-
String code = '''
13830-
import 'helper.dart' as helper;
13831-
main() {
13832-
helper.max(10, 10); // marker
13833-
}''';
13834-
SimpleIdentifier methodName =
13835-
_findMarkedIdentifier(code, "(10, 10); // marker");
13836-
MethodInvocation methodInvoke = methodName.parent;
13837-
expect(methodInvoke.methodName.staticElement, isNotNull);
13838-
expect(methodInvoke.methodName.propagatedElement, isNull);
13839-
}
13840-
1384113834
void fail_mergePropagatedTypesAtJoinPoint_1() {
1384213835
// https://code.google.com/p/dart/issues/detail?id=19929
1384313836
_assertTypeOfMarkedExpression(
@@ -14657,6 +14650,25 @@ main() {
1465714650
}
1465814651
}
1465914652

14653+
void test_invocation_target_prefixed() {
14654+
addNamedSource(
14655+
'/helper.dart',
14656+
'''
14657+
library helper;
14658+
int max(int x, int y) => 0;
14659+
''');
14660+
String code = '''
14661+
import 'helper.dart' as helper;
14662+
main() {
14663+
helper.max(10, 10); // marker
14664+
}''';
14665+
SimpleIdentifier methodName =
14666+
_findMarkedIdentifier(code, "(10, 10); // marker");
14667+
MethodInvocation methodInvoke = methodName.parent;
14668+
expect(methodInvoke.methodName.staticElement, isNotNull);
14669+
expect(methodInvoke.methodName.propagatedElement, isNull);
14670+
}
14671+
1466014672
void test_is_conditional() {
1466114673
Source source = addSource(r'''
1466214674
class A {}

pkg/analyzer/test/src/task/strong/strong_test_helper.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ void testChecker(String name, Map<String, String> testFiles) {
6363
AnalysisEngine.instance.useTaskModel = true;
6464
var context = AnalysisEngine.instance.createAnalysisContext();
6565
context.analysisOptions.strongMode = true;
66+
context.analysisOptions.strongModeHints = true;
6667

6768
context.sourceFactory = new SourceFactory([
6869
new MockDartSdk(mockSdkSources, reportMissing: true).resolver,

0 commit comments

Comments
 (0)