From 06e73efda4913e2e034d5ed8ae2dfbfeddac4bee Mon Sep 17 00:00:00 2001 From: Sigmund Cherem Date: Tue, 17 Mar 2015 14:00:48 -0700 Subject: [PATCH] Turn on infer-from-overrides by default, rename inferStaticFromOtherStatics to inferTransitively. BUG= R=vsm@google.com Review URL: https://codereview.chromium.org/1015843002 --- pkg/dev_compiler/lib/src/checker/resolver.dart | 4 ++-- pkg/dev_compiler/lib/src/options.dart | 16 ++++++++-------- pkg/dev_compiler/lib/src/testing.dart | 4 ++-- .../test/checker/inferred_type_test.dart | 16 ++++++++-------- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/pkg/dev_compiler/lib/src/checker/resolver.dart b/pkg/dev_compiler/lib/src/checker/resolver.dart index 0464a7b7950..596de962cbd 100644 --- a/pkg/dev_compiler/lib/src/checker/resolver.dart +++ b/pkg/dev_compiler/lib/src/checker/resolver.dart @@ -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); } diff --git a/pkg/dev_compiler/lib/src/options.dart b/pkg/dev_compiler/lib/src/options.dart index 3dcd1fa6079..968ce65508a 100644 --- a/pkg/dev_compiler/lib/src/options.dart +++ b/pkg/dev_compiler/lib/src/options.dart @@ -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 [], 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 [], 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 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) diff --git a/pkg/dev_compiler/lib/src/testing.dart b/pkg/dev_compiler/lib/src/testing.dart index e1af56d7089..bdb3120b37d 100644 --- a/pkg/dev_compiler/lib/src/testing.dart +++ b/pkg/dev_compiler/lib/src/testing.dart @@ -51,7 +51,7 @@ CheckerResults testChecker(Map 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 testFiles, covariantGenerics: covariantGenerics, relaxedCasts: relaxedCasts, inferFromOverrides: inferFromOverrides, - inferStaticsFromIdentifiers: inferStaticsFromIdentifiers, + inferTransitively: inferTransitively, nonnullableTypes: nonnullableTypes, useMockSdk: sdkDir == null, dartSdkPath: sdkDir, diff --git a/pkg/dev_compiler/test/checker/inferred_type_test.dart b/pkg/dev_compiler/test/checker/inferred_type_test.dart index accbecb73f9..e9c8d7737c9 100644 --- a/pkg/dev_compiler/test/checker/inferred_type_test.dart +++ b/pkg/dev_compiler/test/checker/inferred_type_test.dart @@ -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', () {