Skip to content

Commit

Permalink
Version 3.2.0-118.0.dev
Browse files Browse the repository at this point in the history
Merge 1af5ffc into dev
  • Loading branch information
Dart CI committed Aug 29, 2023
2 parents 2900ad2 + 1af5ffc commit 60a3bb8
Show file tree
Hide file tree
Showing 20 changed files with 282 additions and 54 deletions.
8 changes: 4 additions & 4 deletions DEPS
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,18 @@ vars = {
"fixnum_rev": "00fa1207768bd07d04c895cbe0f1fe99af14e727",
"glob_rev": "5b243935154daf53c54981b98f625bace90b2112",
"html_rev": "4060496b0443451c38f8b789db2e44c0d7966171",
"http_rev": "631d4ec1bcea311a4208b4e5e06031f0307ac9f0",
"http_rev": "cad7d609b18512d74cc30ef8ad9faf02d2ea4451",
"http_multi_server_rev": "aa128cfaf6ef1c9c1ace962ca2dcf6e5dddad441",
"http_parser_rev": "c14fbf6aa7ada5e8912eab4581eb26ff4d101452",
"intl_rev": "5d65e3808ce40e6282e40881492607df4e35669f",
"json_rpc_2_rev": "509f71eef90ec5afb5486b69dab7fed97b9f1eef",
"leak_tracker_rev": "098bafcf99a5220e3c352d895d991e163568ee03", # b/292240713
"lints_rev": "54cd7a033881ccfd9ec66133bf9a4f128870cb9e",
"logging_rev": "521498757ed3eeae151c2d4796404e8947baa04c",
"markdown_rev": "faabb1ab9adc076a2df2349a0c8b939c92f70ca7",
"markdown_rev": "56e75df897ac01a886358e79124844977aa8157c",
"matcher_rev": "ce8f40934c90e12992071172795b3bca29fac295",
"mime_rev": "799b398140817fdb134f639d84e91c552e129136",
"mockito_rev": "70aabfc237c3d0e1a44389011f3d291838ba32df",
"mockito_rev": "f5abf11f8e21e61eebc2081e322bdfcab057e988",
"native_rev": "5a1361b6d98a84f8070c97872e3d3587fc0ba435",
"package_config_rev": "981c49dfec1e3e3e90f336dcd7c225923d2fd321",
"path_rev": "7c2324bdb4c75a17de8a3d1e6afe8cc0756ef5f9",
Expand All @@ -179,7 +179,7 @@ vars = {
"test_descriptor_rev": "36d8617fafccbe36dfcf74ad4921c61911a6a411",
"test_process_rev": "b360784a9149b15888aed8d7cf167bb46fe733d5",
"test_reflective_loader_rev": "0bfaad91ed308ce9da11b48395c8210d7542c16b",
"tools_rev": "e5ce42a724cbf96877b0802f69da637d4fa63dee",
"tools_rev": "b72fae8673a5fa30b0eff4077005ac95f960dc9b",
"typed_data_rev": "a20be901e11eddcbd6e5735fb01b64d28c94c49d",
"usage_rev": "09bb8472fdafff2c48a19aabbcf57b3af0f43934",
"vector_math_rev": "88bada3c32ba3f1d53073a003085131d60b09213",
Expand Down
26 changes: 2 additions & 24 deletions pkg/_fe_analyzer_shared/lib/src/util/colors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,6 @@ String magenta(String string) => wrap(string, MAGENTA_COLOR);
String cyan(String string) => wrap(string, CYAN_COLOR);
String white(String string) => wrap(string, WHITE_COLOR);

/// Returns whether [sink] supports ANSI escapes or `null` if it could not be
/// determined.
bool? _supportsAnsiEscapes(sink) {
try {
return sink.supportsAnsiEscapes;
} on NoSuchMethodError {
// Ignored: We're running on an older version of the Dart VM which doesn't
// implement `supportsAnsiEscapes`.
return null;
}
}

/// Callback used by [_computeEnableColors] to report why it has or hasn't
/// chosen to use ANSI colors.
void Function(String) printEnableColorsReason = (_) {};
Expand All @@ -130,28 +118,18 @@ void Function(String) printEnableColorsReason = (_) {};
/// Note: do not call this method directly, as it is expensive to
/// compute. Instead, use [CompilerContext.enableColors].
bool _computeEnableColors() {
bool? stderrSupportsColors = _supportsAnsiEscapes(stdout);
bool? stdoutSupportsColors = _supportsAnsiEscapes(stderr);

if (stdoutSupportsColors == false) {
if (!stdout.supportsAnsiEscapes) {
printEnableColorsReason(
"Not enabling colors, stdout does not support ANSI colors.");
return false;
}
if (stderrSupportsColors == false) {
if (!stderr.supportsAnsiEscapes) {
printEnableColorsReason(
"Not enabling colors, stderr does not support ANSI colors.");
return false;
}

if (Platform.isWindows) {
if (stderrSupportsColors != true || stdoutSupportsColors != true) {
// In this case, either [stdout] or [stderr] did not support the
// property `supportsAnsiEscapes`. Since we do not have another way
// to determine support for colors, we disable them.
printEnableColorsReason("Not enabling colors as ANSI is not supported.");
return false;
}
printEnableColorsReason("Enabling colors as OS is Windows.");
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,10 @@ CompileTimeErrorCode.EXTENSION_TYPE_INHERITED_MEMBER_CONFLICT:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_DEPENDS_ON_ITSELF:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER:
status: needsFix
notes: |-
Convert to block body.
CompileTimeErrorCode.EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER:
status: needsFix
notes: |-
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import 'package:analyzer/instrumentation/instrumentation.dart';
import 'package:analyzer/src/test_utilities/resource_provider_mixin.dart';
import 'package:test/test.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';
// TODO(dantup): Survey isn't currently publicly exported.
import 'package:unified_analytics/src/survey_handler.dart' show Survey;
import 'package:unified_analytics/unified_analytics.dart';

void main() {
Expand Down
10 changes: 10 additions & 0 deletions pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1705,6 +1705,16 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
correctionMessage: "Try specifying a different type.",
);

/// Parameters:
/// 0: the name of the abstract method
/// 1: the name of the enclosing extension type
static const CompileTimeErrorCode EXTENSION_TYPE_WITH_ABSTRACT_MEMBER =
CompileTimeErrorCode(
'EXTENSION_TYPE_WITH_ABSTRACT_MEMBER',
"'{0}' must have a method body because '{1}' is an extension type.",
correctionMessage: "Try adding a body to '{0}'.",
);

static const CompileTimeErrorCode EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER =
CompileTimeErrorCode(
'EXTERNAL_WITH_INITIALIZER',
Expand Down
5 changes: 3 additions & 2 deletions pkg/analyzer/lib/src/error/duplicate_definition_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,10 @@ class DuplicateDefinitionVerifier {
if (declarationElement == null) return;

final primaryConstructorName = element.constructors.first.name;
final representationGetter = element.representation.getter!;
_getElementContext(declarationElement)
.constructorNames
.add(primaryConstructorName);
..constructorNames.add(primaryConstructorName)
..instanceGetters[representationGetter.name] = representationGetter;

_checkClassMembers(element, node.members);
}
Expand Down
1 change: 1 addition & 0 deletions pkg/analyzer/lib/src/error/error_code_values.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ const List<ErrorCode> errorCodeValues = [
CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_REPRESENTATION_NOT_SUPERTYPE,
CompileTimeErrorCode.EXTENSION_TYPE_INHERITED_MEMBER_CONFLICT,
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_DEPENDS_ON_ITSELF,
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER,
CompileTimeErrorCode.EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER,
CompileTimeErrorCode.EXTERNAL_FIELD_INITIALIZER,
CompileTimeErrorCode.EXTERNAL_VARIABLE_INITIALIZER,
Expand Down
19 changes: 18 additions & 1 deletion pkg/analyzer/lib/src/generated/error_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
node: node,
element: element,
);
_checkForExtensionTypeWithAbstractMember(node);

super.visitExtensionTypeDeclaration(node);
} finally {
Expand Down Expand Up @@ -2870,7 +2871,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
return;
}

if (node.isStatic) {
if (node.isStatic || node.externalKeyword != null) {
return;
}

Expand Down Expand Up @@ -2961,6 +2962,22 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
}

void _checkForExtensionTypeWithAbstractMember(
ExtensionTypeDeclarationImpl node,
) {
for (final member in node.members) {
if (member is MethodDeclarationImpl && !member.isStatic) {
if (member.isAbstract) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER,
member,
[member.name.lexeme, node.name.lexeme],
);
}
}
}
}

/// Verify that the given field formal [parameter] is in a constructor
/// declaration.
///
Expand Down
7 changes: 7 additions & 0 deletions pkg/analyzer/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5154,6 +5154,13 @@ CompileTimeErrorCode:
problemMessage: "The extension type representation can't depend on itself."
correctionMessage: Try specifying a different type.
comment: No parameters.
EXTENSION_TYPE_WITH_ABSTRACT_MEMBER:
problemMessage: "'{0}' must have a method body because '{1}' is an extension type."
correctionMessage: "Try adding a body to '{0}'."
comment: |-
Parameters:
0: the name of the abstract method
1: the name of the enclosing extension type
EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER:
sharedName: EXTERNAL_WITH_INITIALIZER
problemMessage: External fields can't have initializers.
Expand Down
30 changes: 30 additions & 0 deletions pkg/analyzer/test/src/diagnostics/duplicate_definition_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1222,6 +1222,36 @@ extension type E(int it) {
]);
}

test_instance_representation_getter() async {
await assertErrorsInCode(r'''
extension type E(int it) {
int get it => 0;
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 37, 2,
contextMessages: [message('/home/test/lib/test.dart', 21, 2)]),
]);
}

test_instance_representation_method() async {
await assertErrorsInCode(r'''
extension type E(int it) {
void it() {}
}
''', [
error(CompileTimeErrorCode.DUPLICATE_DEFINITION, 34, 2,
contextMessages: [message('/home/test/lib/test.dart', 21, 2)]),
]);
}

test_instance_representation_setter() async {
await assertNoErrorsInCode(r'''
extension type E(int it) {
set it(int _) {}
}
''');
}

test_instance_setter_getter() async {
await assertNoErrorsInCode(r'''
extension type E(int it) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ extension type E(int it) {
]);
}

test_instance_field_external() async {
await assertNoErrorsInCode('''
extension type E(int it) {
external int foo;
}
''');
}

test_instance_getter() async {
await assertNoErrorsInCode('''
extension type E(int it) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
// Copyright (c) 2023, 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:analyzer/src/dart/error/syntactic_errors.dart';
import 'package:analyzer/src/error/codes.dart';
import 'package:test_reflective_loader/test_reflective_loader.dart';

import '../dart/resolution/context_collection_resolution.dart';

main() {
defineReflectiveSuite(() {
defineReflectiveTests(ExtensionTypeWithAbstractMemberTest);
});
}

@reflectiveTest
class ExtensionTypeWithAbstractMemberTest extends PubPackageResolutionTest {
test_getter() async {
await assertErrorsInCode('''
extension type A(int it) {
int get foo;
}
''', [
error(CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER, 29, 12),
]);
}

test_getter_external() async {
await assertNoErrorsInCode('''
extension type A(int it) {
external int get foo;
}
''');
}

test_getter_static() async {
await assertErrorsInCode('''
extension type A(int it) {
static int get foo;
}
''', [
error(ParserErrorCode.MISSING_FUNCTION_BODY, 47, 1),
]);
}

test_method() async {
await assertErrorsInCode('''
extension type A(int it) {
void foo();
}
''', [
error(CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER, 29, 11),
]);
}

test_method_external() async {
await assertNoErrorsInCode('''
extension type A(int it) {
external void foo();
}
''');
}

test_method_static() async {
await assertErrorsInCode('''
extension type A(int it) {
static void foo();
}
''', [
error(ParserErrorCode.MISSING_FUNCTION_BODY, 46, 1),
]);
}

test_setter() async {
await assertErrorsInCode('''
extension type A(int it) {
set foo(int _);
}
''', [
error(CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER, 29, 15),
]);
}

test_setter_external() async {
await assertNoErrorsInCode('''
extension type A(int it) {
external set foo(int _);
}
''');
}

test_setter_static() async {
await assertErrorsInCode('''
extension type A(int it) {
static set foo(int _);
}
''', [
error(ParserErrorCode.MISSING_FUNCTION_BODY, 50, 1),
]);
}
}
3 changes: 3 additions & 0 deletions pkg/analyzer/test/src/diagnostics/test_all.dart
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,8 @@ import 'extension_type_inherited_member_conflict_test.dart'
as extension_type_inherited_member_conflict;
import 'extension_type_representation_depends_on_itself_test.dart'
as extension_type_representation_depends_on_itself;
import 'extension_type_with_abstract_member_test.dart'
as extension_type_with_abstract_member;
import 'external_field_constructor_initializer_test.dart'
as external_field_constructor_initializer;
import 'external_field_initializer_test.dart' as external_field_initializer;
Expand Down Expand Up @@ -1067,6 +1069,7 @@ main() {
extension_type_implements_representation_not_supertype.main();
extension_type_inherited_member_conflict.main();
extension_type_representation_depends_on_itself.main();
extension_type_with_abstract_member.main();
external_field_constructor_initializer.main();
external_field_initializer.main();
external_variable_initializer.main();
Expand Down
3 changes: 1 addition & 2 deletions pkg/front_end/test/static_types/cfe_allowed.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"Dynamic invocation of '[]='.": 1
},
"pkg/_fe_analyzer_shared/lib/src/util/colors.dart": {
"Dynamic access of 'supportsAnsiEscapes'.": 1,
"Dynamic invocation of 'split'.": 1
},
"pkg/_fe_analyzer_shared/lib/src/scanner/token_impl.dart": {
Expand All @@ -16,4 +15,4 @@
"pkg/front_end/lib/src/fasta/dill/dill_member_builder.dart": {
"Dynamic access of 'fileUri'.": 1
}
}
}
Loading

0 comments on commit 60a3bb8

Please sign in to comment.