Skip to content

Commit

Permalink
Version 3.3.0-42.0.dev
Browse files Browse the repository at this point in the history
Merge 13791e4 into dev
  • Loading branch information
Dart CI committed Oct 19, 2023
2 parents d9b1e60 + 13791e4 commit eb3fb9a
Show file tree
Hide file tree
Showing 898 changed files with 403 additions and 81,426 deletions.
1 change: 0 additions & 1 deletion BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,6 @@ if (is_fuchsia) {
dart_fuchsia_test_component("fuchsia_test_component") {
manifest = "build/fuchsia/fuchsia_test_component.cmx"
resource_dirs = [
"tests/standalone_2",
"pkg/async_helper",
"pkg/expect",
"pkg/meta",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ class CreateGetter extends CreateFieldOrGetter {
if (targetNode is CompilationUnitMember) {
if (targetDeclarationResult.node is! ClassDeclaration &&
targetDeclarationResult.node is! ExtensionDeclaration &&
targetDeclarationResult.node is! ExtensionTypeDeclaration &&
targetDeclarationResult.node is! MixinDeclaration) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ class CreateSetter extends ResolvedCorrectionProducer {
if (targetNode is CompilationUnitMember) {
if (targetDeclarationResult.node is! ClassDeclaration &&
targetDeclarationResult.node is! MixinDeclaration &&
targetDeclarationResult.node is! ExtensionDeclaration) {
targetDeclarationResult.node is! ExtensionDeclaration &&
targetDeclarationResult.node is! ExtensionTypeDeclaration) {
return;
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,8 @@ CompileTimeErrorCode.EXTENSION_TYPE_INHERITED_MEMBER_CONFLICT:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_DEPENDS_ON_ITSELF:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM:
status: noFix
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER:
status: needsFix
notes: |-
Expand Down
6 changes: 6 additions & 0 deletions pkg/analysis_server/lib/src/services/correction/util.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,8 @@ class CorrectionUtils {
return declaration.leftBracket;
} else if (declaration is MixinDeclaration) {
return declaration.leftBracket;
} else if (declaration is ExtensionTypeDeclaration) {
return declaration.leftBracket;
}
return null;
}
Expand All @@ -1384,6 +1386,8 @@ class CorrectionUtils {
return declaration.members;
} else if (declaration is MixinDeclaration) {
return declaration.members;
} else if (declaration is ExtensionTypeDeclaration) {
return declaration.members;
}
return null;
}
Expand All @@ -1395,6 +1399,8 @@ class CorrectionUtils {
return declaration.rightBracket;
} else if (declaration is MixinDeclaration) {
return declaration.rightBracket;
} else if (declaration is ExtensionTypeDeclaration) {
return declaration.rightBracket;
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,26 @@ class CreateGetterTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.CREATE_GETTER;

Future<void> test_extension_type() async {
await resolveTestCode('''
extension type A(String s) {
}
void f(A a) {
int v = a.test;
print(v);
}
''');
await assertHasFix('''
extension type A(String s) {
int get test => null;
}
void f(A a) {
int v = a.test;
print(v);
}
''');
}

Future<void> test_hint_getter() async {
await resolveTestCode('''
class A {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,24 @@ class CreateSetterTest extends FixProcessorTest {
@override
FixKind get kind => DartFixKind.CREATE_SETTER;

Future<void> test_extension_type() async {
await resolveTestCode('''
extension type A(String s) {
}
void f(A a) {
a.test = 0;
}
''');
await assertHasFix('''
extension type A(String s) {
set test(int test) {}
}
void f(A a) {
a.test = 0;
}
''');
}

Future<void> test_getterContext() async {
await resolveTestCode('''
class A {
Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/lib/src/dart/analysis/results.dart
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,10 @@ class _DeclarationByElementLocator extends UnifyingAstVisitor<void> {
if (_hasOffset2(node.name)) {
result = node;
}
} else if (node is ExtensionTypeDeclaration) {
if (_hasOffset2(node.name)) {
result = node;
}
}
} else if (element is ConstructorElement) {
if (node is ConstructorDeclaration) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/analyzer/lib/src/dart/ast/to_source_visitor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ class ToSourceVisitor implements AstVisitor<void> {
_visitToken(node.name);
_visitNode(node.typeParameters);
_visitNode(node.representation, suffix: ' ');
_visitNode(node.implementsClause, suffix: ' ');
_visitToken(node.leftBracket);
_visitNodeList(node.members, separator: ' ');
_visitToken(node.rightBracket);
Expand Down Expand Up @@ -1167,6 +1168,7 @@ class ToSourceVisitor implements AstVisitor<void> {
void visitRepresentationDeclaration(RepresentationDeclaration node) {
_visitNode(node.constructorName);
_visitToken(node.leftParenthesis);
_visitNodeList(node.fieldMetadata, separator: ' ', suffix: ' ');
_visitNode(node.fieldType, suffix: ' ');
_visitToken(node.fieldName);
_visitToken(node.rightParenthesis);
Expand Down
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/error/codes.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1731,6 +1731,14 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
correctionMessage: "Try specifying a different type.",
);

/// No parameters.
static const CompileTimeErrorCode EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM =
CompileTimeErrorCode(
'EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM',
"The representation type can't be a bottom type.",
correctionMessage: "Try specifying a different type.",
);

/// Parameters:
/// 0: the name of the abstract method
/// 1: the name of the enclosing extension type
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 @@ -208,6 +208,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_REPRESENTATION_TYPE_BOTTOM,
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER,
CompileTimeErrorCode.EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER,
CompileTimeErrorCode.EXTERNAL_FIELD_INITIALIZER,
Expand Down
16 changes: 10 additions & 6 deletions pkg/analyzer/lib/src/fasta/ast_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1789,6 +1789,16 @@ class AstBuilder extends StackListener {
startToken: requiredKeyword,
);
}
// TODO(scheglov) https://github.com/dart-lang/sdk/issues/53324
// If the issue fixed, we can remove this from the analyzer.
if (_classLikeBuilder is _ExtensionTypeDeclarationBuilder &&
covariantKeyword != null) {
errorReporter.errorReporter?.reportErrorForToken(
ParserErrorCode.EXTRANEOUS_MODIFIER,
covariantKeyword,
[covariantKeyword.lexeme],
);
}
var metadata = pop() as List<AnnotationImpl>?;
var comment = _findComment(metadata,
thisKeyword ?? typeOrFunctionTypedParameter?.beginToken ?? nameToken);
Expand Down Expand Up @@ -2815,12 +2825,6 @@ class AstBuilder extends StackListener {
);
break;
}
if (firstFormalParameter.covariantKeyword case final keyword?) {
errorReporter.errorReporter?.reportErrorForToken(
ParserErrorCode.REPRESENTATION_FIELD_MODIFIER,
keyword,
);
}
if (firstFormalParameter.keyword case final keyword?) {
if (keyword.keyword != Keyword.CONST) {
errorReporter.errorReporter?.reportErrorForToken(
Expand Down
16 changes: 16 additions & 0 deletions pkg/analyzer/lib/src/generated/error_verifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -706,12 +706,15 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
_enclosingClass = declarationElement;

_duplicateDefinitionVerifier.checkExtensionType(node, declarationElement);
_checkForRepeatedType(node.implementsClause?.interfaces,
CompileTimeErrorCode.IMPLEMENTS_REPEATED);
_checkForConflictingClassMembers();
_checkForConflictingGenerics(node);
_constructorFieldsVerifier.enterExtensionType(node, declarationElement);
_checkForNonCovariantTypeParameterPositionInRepresentationType(
node, element);
_checkForExtensionTypeRepresentationDependsOnItself(node, element);
_checkForExtensionTypeRepresentationTypeBottom(node, element);
_checkForExtensionTypeImplementsDeferred(node);
_checkForExtensionTypeImplementsItself(node, element);
_checkForExtensionTypeMemberConflicts(
Expand Down Expand Up @@ -2963,6 +2966,19 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
}
}

void _checkForExtensionTypeRepresentationTypeBottom(
ExtensionTypeDeclarationImpl node,
ExtensionTypeElementImpl element,
) {
final representationType = element.representation.type;
if (typeSystem.isBottom(representationType)) {
errorReporter.reportErrorForNode(
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM,
node.representation.fieldType,
);
}
}

void _checkForExtensionTypeWithAbstractMember(
ExtensionTypeDeclarationImpl node,
) {
Expand Down
8 changes: 8 additions & 0 deletions pkg/analyzer/lib/src/summary2/library_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,14 @@ class _FieldPromotability extends FieldPromotability<InterfaceElement,
for (var mixin_ in unitElement.mixins) {
_handleMembers(addClass(mixin_, isAbstract: true), mixin_);
}
// Private representation fields of extension types are always promotable.
// They also don't affect promotability of any other fields.
for (final extensionType in unitElement.extensionTypes) {
final representation = extensionType.representation;
if (representation.name.startsWith('_')) {
representation.isPromotable = true;
}
}
}

// Compute the set of field names that are not promotable.
Expand Down
4 changes: 4 additions & 0 deletions pkg/analyzer/messages.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5165,6 +5165,10 @@ CompileTimeErrorCode:
problemMessage: "The extension type representation can't depend on itself."
correctionMessage: Try specifying a different type.
comment: No parameters.
EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM:
problemMessage: "The representation type can't be a bottom type."
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}'."
Expand Down
32 changes: 32 additions & 0 deletions pkg/analyzer/test/src/dart/ast/to_source_visitor_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@ main() {

@reflectiveTest
class ToSourceVisitorTest extends ParserDiagnosticsTest {
void test_representationDeclaration() {
final code = '(@foo int it)';
final findNode = _parseStringToFindNode('''
extension type E$code {}
''');
_assertSource(code, findNode.singleRepresentationDeclaration);
}

void test_visitAdjacentStrings() {
var findNode = _parseStringToFindNode(r'''
var v = 'a' 'b';
Expand Down Expand Up @@ -1281,6 +1289,30 @@ $code
// [AstTestFactory.identifier3('o')])));
}

void test_visitExtensionType() {
final code = 'extension type E(int it) {}';
final findNode = _parseStringToFindNode('''
$code
''');
_assertSource(code, findNode.singleExtensionTypeDeclaration);
}

void test_visitExtensionType_implements() {
final code = 'extension type E(int it) implements num {}';
final findNode = _parseStringToFindNode('''
$code
''');
_assertSource(code, findNode.singleExtensionTypeDeclaration);
}

void test_visitExtensionType_method() {
final code = 'extension type E(int it) {void foo() {}}';
final findNode = _parseStringToFindNode('''
$code
''');
_assertSource(code, findNode.singleExtensionTypeDeclaration);
}

void test_visitFieldDeclaration_abstract() {
final code = 'abstract var a;';
final findNode = _parseStringToFindNode('''
Expand Down
Loading

0 comments on commit eb3fb9a

Please sign in to comment.