Skip to content

Commit

Permalink
Version 2.14.0-182.0.dev
Browse files Browse the repository at this point in the history
Merge commit 'e1f37f602954681b64ffcd37900f44ef857afd0b' into 'dev'
  • Loading branch information
Dart CI committed Jun 3, 2021
2 parents 202c42e + e1f37f6 commit 2e9c430
Show file tree
Hide file tree
Showing 40 changed files with 753 additions and 632 deletions.
2 changes: 1 addition & 1 deletion benchmarks/SDKArtifactSizes/dart/SDKArtifactSizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const snapshots = <String>[

Future<void> reportArtifactSize(String path, String name) async {
final size = await File(path).length();
print('SDKArtifactSize.$name(CodeSize): $size');
print('SDKArtifactSizes.$name(CodeSize): $size');
}

Future<void> main() async {
Expand Down
2 changes: 1 addition & 1 deletion benchmarks/SDKArtifactSizes/dart2/SDKArtifactSizes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const snapshots = <String>[

Future<void> reportArtifactSize(String path, String name) async {
final size = await File(path).length();
print('SDKArtifactSize.$name(CodeSize): $size');
print('SDKArtifactSizes.$name(CodeSize): $size');
}

Future<void> main() async {
Expand Down
17 changes: 15 additions & 2 deletions pkg/analysis_server/lib/src/cider/rename.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,27 @@

import 'package:analysis_server/src/services/refactoring/refactoring.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:analyzer/src/dart/ast/utilities.dart';
import 'package:analyzer/src/dart/micro/resolve_file.dart';
import 'package:analyzer/src/dart/micro/utils.dart';

class CanRenameResponse {
final LineInfo lineInfo;
final RenameRefactoringElement refactoringElement;
final String oldName;

CanRenameResponse(this.lineInfo, this.refactoringElement, this.oldName);
}

class CiderRenameComputer {
final FileResolver _fileResolver;

CiderRenameComputer(this._fileResolver);

/// Check if the identifier at the [line], [column] for the file at the
/// [filePath] can be renamed.
RenameRefactoringElement? canRename(String filePath, int line, int column) {
CanRenameResponse? canRename(String filePath, int line, int column) {
var resolvedUnit = _fileResolver.resolve(path: filePath);
var lineInfo = resolvedUnit.lineInfo;
var offset = lineInfo.getOffsetOfLine(line) + column;
Expand All @@ -35,7 +44,11 @@ class CiderRenameComputer {
if (!_canRenameElement(element)) {
return null;
}
return RenameRefactoring.getElementToRename(node, element);
var refactoring = RenameRefactoring.getElementToRename(node, element);
if (refactoring != null) {
return CanRenameResponse(lineInfo, refactoring, element.displayName);
}
return null;
}

bool _canRenameElement(Element element) {
Expand Down
27 changes: 13 additions & 14 deletions pkg/analysis_server/test/src/cider/rename_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analysis_server/src/cider/rename.dart';
import 'package:analysis_server/src/services/refactoring/refactoring.dart';
import 'package:analyzer/source/line_info.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
Expand Down Expand Up @@ -31,8 +30,8 @@ class A {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'bar');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'bar');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

void test_canRename_function() {
Expand All @@ -42,8 +41,8 @@ void ^foo() {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'foo');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'foo');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

void test_canRename_label() {
Expand All @@ -58,8 +57,8 @@ main() {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'myLabel');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'myLabel');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

void test_canRename_local() {
Expand All @@ -70,8 +69,8 @@ void foo() {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'a');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'a');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

void test_canRename_method() {
Expand All @@ -82,8 +81,8 @@ extension E on int {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'foo');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'foo');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

void test_canRename_operator() {
Expand All @@ -104,11 +103,11 @@ void foo(int ^bar) {
''');

expect(refactor, isNotNull);
expect(refactor!.element.name, 'bar');
expect(refactor.offset, _correctionContext.offset);
expect(refactor!.refactoringElement.element.name, 'bar');
expect(refactor.refactoringElement.offset, _correctionContext.offset);
}

RenameRefactoringElement? _compute(String content) {
CanRenameResponse? _compute(String content) {
_updateFile(content);

return CiderRenameComputer(
Expand Down
7 changes: 4 additions & 3 deletions pkg/analyzer/lib/src/dart/constant/evaluation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -822,11 +822,12 @@ class ConstantEvaluationEngine {
DartObjectImpl obj,
DartType type,
) {
if (obj.isNull) {
return true;
var typeSystem = library.typeSystem;
if (!typeSystem.isNonNullableByDefault) {
type = typeSystem.toLegacyType(type);
}
var objType = obj.type;
return library.typeSystem.isSubtypeOf(objType, type);
return typeSystem.isSubtypeOf(objType, type);
}

DartObjectImpl _nullObject(LibraryElementImpl library) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/analyzer/test/generated/constant_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class C {
"const Center(name: 'v')",
context: '''
class Align {
final double widthFactor;
final double? widthFactor;
const Align({String name, this.widthFactor})
assert(widthFactor == null || widthFactor >= 0.0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ main() {

@reflectiveTest
class ConstConstructorFieldTypeMismatchTest extends PubPackageResolutionTest {
test_assignable_generic() async {
test_generic_int_int() async {
await assertErrorsInCode(
r'''
class C<T> {
Expand All @@ -31,65 +31,95 @@ var v = const C<int>();
);
}

test_assignable_nullValue() async {
await assertNoErrorsInCode(r'''
class A {
const A(x) : y = x;
final int y;
test_generic_string_int() async {
await assertErrorsInCode(
r'''
class C<T> {
final T x = y;
const C();
}
var v = const A(null);
''');
const int y = 1;
var v = const C<String>();
''',
[
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 27, 1),
error(
CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 70, 17),
],
);
}

test_assignable_unresolvedFieldAndNullValue() async {
test_notGeneric_int_int() async {
await assertErrorsInCode(r'''
class A {
const A(x) : y = x;
final Unresolved y;
final int y;
}
var v = const A(null);
var v = const A('foo');
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 40, 10),
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 57, 14),
]);
}

test_notAssignable() async {
test_notGeneric_int_null() async {
var errors = expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 57, 13),
], legacy: []);
await assertErrorsInCode(r'''
class A {
const A(x) : y = x;
final int y;
}
var v = const A('foo');
var v = const A(null);
''', errors);
}

test_notGeneric_null_forNonNullable_fromLegacy() async {
newFile('$testPackageLibPath/a.dart', content: r'''
class C {
final int f;
const C(a) : f = a;
}
''');
await assertNoErrorsInCode('''
// @dart = 2.9
import 'a.dart';
const a = const C(null);
''');
}

test_notGeneric_null_forNonNullable_fromNullSafe() async {
await assertErrorsInCode('''
class C {
final int f;
const C(a) : f = a;
}
const a = const C(null);
''', [
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 57, 14),
error(CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 60, 13),
]);
}

test_notAssignable_generic() async {
await assertErrorsInCode(
r'''
class C<T> {
final T x = y;
const C();
test_notGeneric_unresolved_int() async {
await assertErrorsInCode(r'''
class A {
const A(x) : y = x;
final Unresolved y;
}
const int y = 1;
var v = const C<String>();
''',
[
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 27, 1),
error(
CompileTimeErrorCode.CONST_CONSTRUCTOR_FIELD_TYPE_MISMATCH, 70, 17),
],
);
var v = const A(0);
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 40, 10),
]);
}

test_notAssignable_unresolved() async {
test_notGeneric_unresolved_null() async {
await assertErrorsInCode(r'''
class A {
const A(x) : y = x;
final Unresolved y;
}
var v = const A('foo');
var v = const A(null);
''', [
error(CompileTimeErrorCode.UNDEFINED_CLASS, 40, 10),
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,19 @@ main() {
defineReflectiveSuite(() {
defineReflectiveTests(ListElementTypeNotAssignableTest);
defineReflectiveTests(ListElementTypeNotAssignableWithNoImplicitCastsTest);
defineReflectiveTests(ListElementTypeNotAssignableWithoutNullSafetyTest);
});
}

@reflectiveTest
class ListElementTypeNotAssignableTest extends PubPackageResolutionTest
with ListElementTypeNotAssignableTestCases {}
with ListElementTypeNotAssignableTestCases {
test_const_stringQuestion_null_value() async {
await assertNoErrorsInCode('''
var v = const <String?>[null];
''');
}
}

mixin ListElementTypeNotAssignableTestCases on PubPackageResolutionTest {
test_const_ifElement_thenElseFalse_intInt() async {
Expand Down Expand Up @@ -68,6 +75,32 @@ var v = const <int>[if (true) a];
]);
}

test_const_intInt() async {
await assertNoErrorsInCode(r'''
var v1 = <int> [42];
var v2 = const <int> [42];
''');
}

test_const_intNull_dynamic() async {
var errors = expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 36, 1),
], legacy: []);
await assertErrorsInCode('''
const a = null;
var v = const <int>[a];
''', errors);
}

test_const_intNull_value() async {
var errors = expectedErrorsByNullability(nullable: [
error(CompileTimeErrorCode.LIST_ELEMENT_TYPE_NOT_ASSIGNABLE, 20, 4),
], legacy: []);
await assertErrorsInCode('''
var v = const <int>[null];
''', errors);
}

test_const_spread_intInt() async {
await assertNoErrorsInCode('''
var v = const <int>[...[0, 1]];
Expand All @@ -91,32 +124,12 @@ var v = const <String>[x];
]);
}

test_const_stringNull() async {
await assertNoErrorsInCode('''
var v = const <String?>[null];
''');
}

test_const_stringNull_dynamic() async {
await assertNoErrorsInCode('''
const dynamic x = null;
var v = const <String>[x];
''');
}

test_const_voidInt() async {
await assertNoErrorsInCode('''
var v = const <void>[42];
''');
}

test_element_type_is_assignable() async {
await assertNoErrorsInCode(r'''
var v1 = <int> [42];
var v2 = const <int> [42];
''');
}

test_nonConst_ifElement_thenElseFalse_intDynamic() async {
await assertNoErrorsInCode('''
const dynamic a = 'a';
Expand Down Expand Up @@ -237,3 +250,8 @@ void f(Iterable<num> a) {
]);
}
}

@reflectiveTest
class ListElementTypeNotAssignableWithoutNullSafetyTest
extends PubPackageResolutionTest
with WithoutNullSafetyMixin, ListElementTypeNotAssignableTestCases {}
Loading

0 comments on commit 2e9c430

Please sign in to comment.