Skip to content

Commit

Permalink
Version 2.11.0-166.0.dev
Browse files Browse the repository at this point in the history
Merge commit '280f639fdaa87575d5e13d3f020c3460da01c414' into 'dev'
  • Loading branch information
Dart CI committed Sep 25, 2020
2 parents adf5469 + 280f639 commit 4fb134a
Show file tree
Hide file tree
Showing 35 changed files with 522 additions and 589 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### Dart2JS

* Removed `--no-defer-class-types` and `--no-new-deferred-split'.

### Tools

#### Dartanalyzer
Expand Down
2 changes: 1 addition & 1 deletion DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ vars = {
"source_maps_rev": "53eb92ccfe6e64924054f83038a534b959b12b3e",
"source_span_rev": "cc7c4288a83f71ecef3414199947b52a8c112c65",
"sse_tag": "e5cf68975e8e87171a3dc297577aa073454a91dc",
"stack_trace_tag": "d3813ca0a77348e0faf0d6af0cc17913e36afa39",
"stack_trace_tag": "a958966148516dfa64e2b54c14492175da5cc8e1",
"stagehand_tag": "v3.3.9",
"stream_channel_tag": "c446774fd077c9bdbd6235a7aadc661ef60a9727",
"string_scanner_rev": "1b63e6e5db5933d7be0a45da6e1129fe00262734",
Expand Down
2 changes: 1 addition & 1 deletion pkg/_fe_analyzer_shared/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: _fe_analyzer_shared
version: 9.0.0
version: 10.0.0
description: Logic that is shared between the front_end and analyzer packages.
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/_fe_analyzer_shared

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,8 @@ class ServerCapabilitiesComputer {
language: 'yaml', scheme: 'file', pattern: '**/pubspec.yaml');
final analysisOptionsFile = DocumentFilter(
language: 'yaml', scheme: 'file', pattern: '**/analysis_options.yaml');
final fixDataFile = DocumentFilter(
language: 'yaml', scheme: 'file', pattern: '**/lib/fix_data.yaml');

final pluginTypes = _server.pluginManager.plugins
.expand((plugin) => plugin.currentSession?.interestingFiles ?? const [])
Expand All @@ -243,6 +245,7 @@ class ServerCapabilitiesComputer {
...allTypes,
pubspecFile,
analysisOptionsFile,
fixDataFile,
}.toList();

final registrations = <Registration>[];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,11 @@ class BulkFixProcessor {
LintNames.prefer_conditional_assignment: [
ReplaceWithConditionalAssignment.newInstance,
],
// TODO (pq): can produce results incompatible w/ `unnecessary_const`
// LintNames.prefer_const_constructors: [
// AddConst.newInstance,
// ReplaceNewWithConst.newInstance,
// ],
LintNames.prefer_const_constructors_in_immutables: [
AddConst.newInstance,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,42 @@ class TransformSetErrorCode extends ErrorCode {
* 0: the actual type of the value
*/
static const TransformSetErrorCode invalidValue = TransformSetErrorCode(
'invalidValue',
'invalid_value',
"The value of '{0}' should be of type '{1}' but is of type '{2}'.");

/**
* Parameters:
* 0: the missing key
*/
static const TransformSetErrorCode missingKey =
TransformSetErrorCode('missingKey', "Missing the required key '{0}'.");
TransformSetErrorCode('missing_key', "Missing the required key '{0}'.");

/**
* No parameters.
*/
static const TransformSetErrorCode missingTemplateEnd = TransformSetErrorCode(
'missingTemplateEnd', "Missing the end brace for the template.");
'missing_template_end', "Missing the end brace for the template.");

/**
* Parameters:
* 0: the missing key
*/
static const TransformSetErrorCode undefinedVariable = TransformSetErrorCode(
'undefinedVariable', "The variable '{0}' is not defined.");
'undefined_variable', "The variable '{0}' is not defined.");

/**
* Parameters:
* 0: the unsupported key
*/
static const TransformSetErrorCode unsupportedKey =
TransformSetErrorCode('unsupportedKey', "The key '{0}' isn't supported.");
static const TransformSetErrorCode unsupportedKey = TransformSetErrorCode(
'unsupported_key', "The key '{0}' isn't supported.");

/**
* Parameters:
* 0: the message produced by the YAML parser
*/
static const TransformSetErrorCode yamlSyntaxError =
TransformSetErrorCode('yamlSyntaxError', "Parse error: {0}");
TransformSetErrorCode('yaml_syntax_error', "Parse error: {0}");

/// Initialize a newly created error code.
const TransformSetErrorCode(String name, String message,
Expand Down
15 changes: 15 additions & 0 deletions pkg/analysis_server/test/lsp/diagnostic_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,21 @@ void f() {
expect(diagnostics, isNull);
}

Future<void> test_fixDataFile() async {
var fixDataPath = join(projectFolderPath, 'lib', 'fix_data.yaml');
var fixDataUri = Uri.file(fixDataPath);
newFile(fixDataPath, content: '''
version: latest
''').path;

final firstDiagnosticsUpdate = waitForDiagnostics(fixDataUri);
await initialize();
final initialDiagnostics = await firstDiagnosticsUpdate;
expect(initialDiagnostics, hasLength(1));
expect(initialDiagnostics.first.severity, DiagnosticSeverity.Error);
expect(initialDiagnostics.first.code, 'invalid_value');
}

Future<void> test_fromPlugins_dartFile() async {
await checkPluginErrorsForFile(mainFilePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,36 @@ import 'bulk_fix_processor.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(AddConstToConstructorTest);
defineReflectiveTests(AddConstToImmutableConstructorTest);
});
}

@reflectiveTest
class AddConstToConstructorTest extends BulkFixProcessorTest {
@override
String get lintCode => LintNames.prefer_const_constructors;

/// Disabled in BulkFixProcessor.
@failingTest
Future<void> test_singleFile() async {
addMetaPackage();
await resolveTestUnit(r'''
class C {
const C([C c]);
}
var c = C(C());
''');
// TODO (pq): results are incompatible w/ `unnecessary_const`
await assertHasFix(r'''
class C {
const C([C c]);
}
var c = const C(const C());
''');
}
}

@reflectiveTest
class AddConstToImmutableConstructorTest extends BulkFixProcessorTest {
@override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/services/linter/lint_names.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import 'bulk_fix_processor.dart';

void main() {
defineReflectiveSuite(() {
defineReflectiveTests(ReplaceNewWithConstTest);
});
}

@reflectiveTest
class ReplaceNewWithConstTest extends BulkFixProcessorTest {
@override
String get lintCode => LintNames.prefer_const_constructors;

/// Disabled in BulkFixProcessor.
@failingTest
Future<void> test_singleFile() async {
await resolveTestUnit(r'''
class C {
const C();
}
main() {
print('${new C()} ${new C()}');
}
''');
await assertHasFix(r'''
class C {
const C();
}
main() {
print('${const C()} ${const C()}');
}
''');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import 'remove_unnecessary_new_test.dart' as remove_unnecessary_new;
import 'rename_to_camel_case_test.dart' as rename_to_camel_case;
import 'replace_colon_with_equals_test.dart' as replace_colon_with_equals;
import 'replace_final_with_const_test.dart' as replace_final_with_const;
import 'replace_new_with_const_test.dart' as replace_new_with_const;
import 'replace_null_with_closure_test.dart' as replace_null_with_closure;
import 'replace_with_conditional_assignment_test.dart'
as replace_with_conditional_assignment;
Expand Down Expand Up @@ -102,6 +103,7 @@ void main() {
replace_with_conditional_assignment.main();
replace_colon_with_equals.main();
replace_final_with_const.main();
replace_new_with_const.main();
replace_null_with_closure.main();
replace_with_is_empty.main();
replace_with_tear_off.main();
Expand Down
5 changes: 5 additions & 0 deletions pkg/analyzer/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## 0.40.3
* Updated the current language version to `2.11`.
* Bug fixes: 43541, 27896, 28066, 28066, 43497, 43478, 28066, 43465,
43462, 43439, 43162, 43397, 43200.

## 0.40.2
* Require `meta: ^1.2.3`.

Expand Down
3 changes: 1 addition & 2 deletions pkg/analyzer/lib/src/dart/ast/ast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8092,8 +8092,7 @@ class PostfixExpressionImpl extends ExpressionImpl
}

@override
bool _extendsNullShorting(Expression child) =>
operator.type != TokenType.BANG && identical(child, operand);
bool _extendsNullShorting(Expression child) => identical(child, operand);
}

/// An identifier that is prefixed or an access to an object property where the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import 'package:analyzer/error/listener.dart';
import 'package:analyzer/src/dart/ast/ast.dart';
import 'package:analyzer/src/dart/element/type.dart';
import 'package:analyzer/src/dart/element/type_algebra.dart';
import 'package:analyzer/src/dart/element/type_provider.dart';
import 'package:analyzer/src/dart/element/type_system.dart';
import 'package:analyzer/src/dart/resolver/flow_analysis_visitor.dart';
import 'package:analyzer/src/error/codes.dart';
Expand All @@ -22,7 +21,6 @@ class InvocationInferenceHelper {
final ErrorReporter _errorReporter;
final FlowAnalysisHelper _flowAnalysis;
final TypeSystemImpl _typeSystem;
final TypeProviderImpl _typeProvider;
final MigrationResolutionHooks _migrationResolutionHooks;

List<DartType> _typeArgumentTypes;
Expand All @@ -37,7 +35,6 @@ class InvocationInferenceHelper {
: _resolver = resolver,
_errorReporter = errorReporter,
_typeSystem = typeSystem,
_typeProvider = typeSystem.typeProvider,
_flowAnalysis = flowAnalysis,
_migrationResolutionHooks = migrationResolutionHooks;

Expand Down Expand Up @@ -157,45 +154,6 @@ class InvocationInferenceHelper {
return null;
}

/// Given a method invocation [node], attempt to infer a better
/// type for the result if the target is dynamic and the method
/// being called is one of the object methods.
bool inferMethodInvocationObject(MethodInvocation node) {
// If we have a call like `toString()` or `libraryPrefix.toString()`, don't
// infer it.
Expression target = node.realTarget;
if (target == null ||
target is SimpleIdentifier && target.staticElement is PrefixElement) {
return false;
}
DartType nodeType = node.staticInvokeType;
if (nodeType == null ||
!nodeType.isDynamic ||
node.argumentList.arguments.isNotEmpty) {
return false;
}
// Object methods called on dynamic targets can have their types improved.
String name = node.methodName.name;
MethodElement inferredElement =
_typeProvider.objectType.element.getMethod(name);
if (inferredElement == null || inferredElement.isStatic) {
return false;
}
inferredElement = _resolver.toLegacyElement(inferredElement);
DartType inferredType = inferredElement.type;
if (inferredType is FunctionType) {
DartType returnType = inferredType.returnType;
if (inferredType.parameters.isEmpty &&
returnType is InterfaceType &&
_typeProvider.nonSubtypableClasses.contains(returnType.element)) {
node.staticInvokeType = inferredType;
recordStaticType(node, inferredType.returnType);
return true;
}
}
return false;
}

/// Given an uninstantiated generic function type, referenced by the
/// [identifier] in the tear-off [expression], try to infer the instantiated
/// generic function type from the surrounding context.
Expand Down
44 changes: 32 additions & 12 deletions pkg/analyzer/lib/src/dart/resolver/method_invocation_resolver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ class MethodInvocationResolver {
}

if (receiverType is DynamicTypeImpl) {
_resolveReceiverDynamic(node, name);
_resolveReceiverDynamic(node);
return;
}

Expand Down Expand Up @@ -291,15 +291,10 @@ class MethodInvocationResolver {
node.methodName.staticType,
);

// TODO(scheglov) Call this only when member lookup failed?
var inferred = _inferenceHelper.inferMethodInvocationObject(node);

if (!inferred) {
DartType staticStaticType = _inferenceHelper.computeInvokeReturnType(
node.staticInvokeType,
);
_inferenceHelper.recordStaticType(node, staticStaticType);
}
DartType staticStaticType = _inferenceHelper.computeInvokeReturnType(
node.staticInvokeType,
);
_inferenceHelper.recordStaticType(node, staticStaticType);
}

/// Given that we are accessing a property of the given [classElement] with the
Expand Down Expand Up @@ -387,8 +382,33 @@ class MethodInvocationResolver {
_setResolution(node, member.type);
}

void _resolveReceiverDynamic(MethodInvocation node, String name) {
_setDynamicResolution(node);
void _resolveReceiverDynamic(MethodInvocationImpl node) {
var nameNode = node.methodName;

var objectElement = _typeSystem.typeProvider.objectElement;
var target = objectElement.getMethod(nameNode.name);

var hasMatchingObjectMethod = false;
if (target is MethodElement) {
var arguments = node.argumentList.arguments;
hasMatchingObjectMethod = arguments.length == target.parameters.length &&
!arguments.any((e) => e is NamedExpression);
if (hasMatchingObjectMethod) {
target = _resolver.toLegacyElement(target);
nameNode.staticElement = target;
node.staticInvokeType = target.type;
node.staticType = target.returnType;
}
}

if (!hasMatchingObjectMethod) {
nameNode.staticType = DynamicTypeImpl.instance;
node.staticInvokeType = DynamicTypeImpl.instance;
node.staticType = DynamicTypeImpl.instance;
}

_setExplicitTypeArgumentTypes();
node.argumentList.accept(_resolver);
}

void _resolveReceiverFunctionType(MethodInvocation node, Expression receiver,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ class PostfixExpressionResolver {
var type = _typeSystem.promoteToNonNull(operandType);
_inferenceHelper.recordStaticType(node, type);

_resolver.nullShortingTermination(node);
_flowAnalysis?.flow?.nonNullAssert_end(operand);
}
}
4 changes: 2 additions & 2 deletions pkg/analyzer/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: analyzer
version: 0.40.2
version: 0.40.3
description: This package provides a library that performs static analysis of Dart code.
homepage: https://github.com/dart-lang/sdk/tree/master/pkg/analyzer

environment:
sdk: '>=2.7.0 <3.0.0'

dependencies:
_fe_analyzer_shared: ^9.0.0
_fe_analyzer_shared: ^10.0.0
args: ^1.0.0
charcode: ^1.1.2
cli_util: '>=0.1.4 <0.3.0'
Expand Down
Loading

0 comments on commit 4fb134a

Please sign in to comment.