Turn on infer-from-overrides by default, rename inferStaticFromOtherStatics to
inferTransitively. BUG= R=vsm@google.com Review URL: https://codereview.chromium.org/1015843002
This commit is contained in:
@@ -324,11 +324,11 @@ class LibraryResolverWithInference extends LibraryResolver {
|
||||
return _canInferFrom(expression.target);
|
||||
}
|
||||
if (expression is SimpleIdentifier || expression is PropertyAccess) {
|
||||
return _options.inferStaticsFromIdentifiers;
|
||||
return _options.inferTransitively;
|
||||
}
|
||||
if (expression is PrefixedIdentifier) {
|
||||
if (expression.staticElement is PropertyAccessorElement) {
|
||||
return _options.inferStaticsFromIdentifiers;
|
||||
return _options.inferTransitively;
|
||||
}
|
||||
return _canInferFrom(expression.identifier);
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class ResolverOptions {
|
||||
|
||||
/// Whether to infer return types and field types from overriden members.
|
||||
final bool inferFromOverrides;
|
||||
static const inferFromOverridesDefault = false;
|
||||
static const inferFromOverridesDefault = true;
|
||||
|
||||
/// Whether to infer types for consts and fields by looking at initializers on
|
||||
/// the RHS. For example, in a constant declaration like:
|
||||
@@ -43,8 +43,8 @@ class ResolverOptions {
|
||||
/// In the future, inference might track dependencies between variables in
|
||||
/// more detail so that, in the example above, we can use `B`'s inferred type
|
||||
/// always.
|
||||
final bool inferStaticsFromIdentifiers;
|
||||
static const inferStaticsFromIdentifiersDefault = false;
|
||||
final bool inferTransitively;
|
||||
static const inferTransitivelyDefault = false;
|
||||
|
||||
/// Restrict inference of fields and top-levels to those that are final and
|
||||
/// const.
|
||||
@@ -54,7 +54,7 @@ class ResolverOptions {
|
||||
ResolverOptions({this.useMultiPackage: false, this.packageRoot: 'packages/',
|
||||
this.packagePaths: const <String>[],
|
||||
this.inferFromOverrides: inferFromOverridesDefault,
|
||||
this.inferStaticsFromIdentifiers: inferStaticsFromIdentifiersDefault,
|
||||
this.inferTransitively: inferTransitivelyDefault,
|
||||
this.onlyInferConstsAndFinalFields: onlyInferConstAndFinalFieldsDefault});
|
||||
}
|
||||
|
||||
@@ -172,7 +172,7 @@ class CompilerOptions implements RulesOptions, ResolverOptions, JSCodeOptions {
|
||||
/// Whether to infer types for consts and static fields by looking at
|
||||
/// identifiers on the RHS.
|
||||
@override
|
||||
final bool inferStaticsFromIdentifiers;
|
||||
final bool inferTransitively;
|
||||
|
||||
/// Restrict inference of fields and top-levels to those that are final and
|
||||
/// const.
|
||||
@@ -200,7 +200,7 @@ class CompilerOptions implements RulesOptions, ResolverOptions, JSCodeOptions {
|
||||
this.useMultiPackage: false, this.packageRoot: 'packages/',
|
||||
this.packagePaths: const <String>[],
|
||||
this.inferFromOverrides: ResolverOptions.inferFromOverridesDefault,
|
||||
this.inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifiersDefault,
|
||||
this.inferTransitively: ResolverOptions.inferTransitivelyDefault,
|
||||
this.onlyInferConstsAndFinalFields: ResolverOptions.onlyInferConstAndFinalFieldsDefault,
|
||||
this.nonnullableTypes: TypeOptions.NONNULLABLE_TYPES, this.help: false,
|
||||
this.useMockSdk: false, this.dartSdkPath, this.logLevel: Level.SEVERE,
|
||||
@@ -235,7 +235,7 @@ CompilerOptions parseOptions(List<String> argv) {
|
||||
packageRoot: args['package-root'],
|
||||
packagePaths: args['package-paths'].split(','),
|
||||
inferFromOverrides: args['infer-from-overrides'],
|
||||
inferStaticsFromIdentifiers: args['infer-transitively'],
|
||||
inferTransitively: args['infer-transitively'],
|
||||
onlyInferConstsAndFinalFields: args['infer-only-finals'],
|
||||
nonnullableTypes: optionsToList(args['nonnullable'],
|
||||
defaultValue: TypeOptions.NONNULLABLE_TYPES),
|
||||
@@ -274,7 +274,7 @@ final ArgParser argParser = new ArgParser()
|
||||
defaultsTo: ResolverOptions.inferFromOverridesDefault)
|
||||
..addFlag('infer-transitively',
|
||||
help: 'Infer consts/fields from definitions in other libraries',
|
||||
defaultsTo: ResolverOptions.inferStaticsFromIdentifiersDefault)
|
||||
defaultsTo: ResolverOptions.inferTransitivelyDefault)
|
||||
..addFlag('infer-only-finals',
|
||||
help: 'Do not infer non-const or non-final fields',
|
||||
defaultsTo: ResolverOptions.onlyInferConstAndFinalFieldsDefault)
|
||||
|
||||
@@ -51,7 +51,7 @@ CheckerResults testChecker(Map<String, String> testFiles,
|
||||
{bool allowConstCasts: true, String sdkDir, CheckerReporter reporter,
|
||||
covariantGenerics: true, relaxedCasts: true,
|
||||
inferFromOverrides: ResolverOptions.inferFromOverridesDefault,
|
||||
inferStaticsFromIdentifiers: ResolverOptions.inferStaticsFromIdentifiersDefault,
|
||||
inferTransitively: ResolverOptions.inferTransitivelyDefault,
|
||||
nonnullableTypes: TypeOptions.NONNULLABLE_TYPES}) {
|
||||
expect(testFiles.containsKey('/main.dart'), isTrue,
|
||||
reason: '`/main.dart` is missing in testFiles');
|
||||
@@ -63,7 +63,7 @@ CheckerResults testChecker(Map<String, String> testFiles,
|
||||
covariantGenerics: covariantGenerics,
|
||||
relaxedCasts: relaxedCasts,
|
||||
inferFromOverrides: inferFromOverrides,
|
||||
inferStaticsFromIdentifiers: inferStaticsFromIdentifiers,
|
||||
inferTransitively: inferTransitively,
|
||||
nonnullableTypes: nonnullableTypes,
|
||||
useMockSdk: sdkDir == null,
|
||||
dartSdkPath: sdkDir,
|
||||
|
||||
@@ -236,7 +236,7 @@ void main() {
|
||||
y = /*severe:StaticTypeError*/"hi";
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
|
||||
testChecker({
|
||||
'/a.dart': '''
|
||||
@@ -251,7 +251,7 @@ void main() {
|
||||
B.y = /*severe:StaticTypeError*/"hi";
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('do not infer from variables in cycle libs', () {
|
||||
@@ -270,7 +270,7 @@ void main() {
|
||||
t = /*info:DownCast*/y;
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
|
||||
testChecker({
|
||||
'/a.dart': '''
|
||||
@@ -287,7 +287,7 @@ void main() {
|
||||
t = /*info:DownCast*/A.y;
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('do not infer from static and instance fields', () {
|
||||
@@ -343,7 +343,7 @@ void main() {
|
||||
x = new A().a2;
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('inference uses declared types', () {
|
||||
@@ -363,7 +363,7 @@ void main() {
|
||||
a = /*info:DownCast*/z;
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('inference in cycles is deterministic', () {
|
||||
@@ -450,7 +450,7 @@ void main() {
|
||||
x = new F().f2;
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('infer from complex expressions if the outer-most value is precise', () {
|
||||
@@ -559,7 +559,7 @@ void main() {
|
||||
i = new B().y; // B.y was inferred though
|
||||
}
|
||||
'''
|
||||
}, inferStaticsFromIdentifiers: true);
|
||||
}, inferTransitively: true);
|
||||
});
|
||||
|
||||
test('infer types on loop indices', () {
|
||||
|
||||
Reference in New Issue
Block a user