mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 14:59:41 +00:00
Extension type. Report when the representation type is a bottom type.
See 3ecf3a729a
Change-Id: If58e262fb913a11edd8f0ecf3f2dcba6879ee65b
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331086
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
This commit is contained in:
parent
5bed3cc23a
commit
13791e4fee
|
@ -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: |-
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -714,6 +714,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
|
|||
_checkForNonCovariantTypeParameterPositionInRepresentationType(
|
||||
node, element);
|
||||
_checkForExtensionTypeRepresentationDependsOnItself(node, element);
|
||||
_checkForExtensionTypeRepresentationTypeBottom(node, element);
|
||||
_checkForExtensionTypeImplementsDeferred(node);
|
||||
_checkForExtensionTypeImplementsItself(node, element);
|
||||
_checkForExtensionTypeMemberConflicts(
|
||||
|
@ -2965,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,
|
||||
) {
|
||||
|
|
|
@ -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}'."
|
||||
|
|
|
@ -224,6 +224,8 @@ class B implements I<num> {}
|
|||
extension type C(Never it) implements A, B {}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 87, 1),
|
||||
error(CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM, 89,
|
||||
5),
|
||||
]);
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
// 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/error/codes.dart';
|
||||
import 'package:test_reflective_loader/test_reflective_loader.dart';
|
||||
|
||||
import '../dart/resolution/context_collection_resolution.dart';
|
||||
|
||||
main() {
|
||||
defineReflectiveSuite(() {
|
||||
defineReflectiveTests(ExtensionTypeRepresentationTypeBottomTest);
|
||||
});
|
||||
}
|
||||
|
||||
@reflectiveTest
|
||||
class ExtensionTypeRepresentationTypeBottomTest
|
||||
extends PubPackageResolutionTest {
|
||||
test_never() async {
|
||||
await assertErrorsInCode('''
|
||||
extension type A(Never it) {}
|
||||
''', [
|
||||
error(CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM, 17,
|
||||
5),
|
||||
]);
|
||||
}
|
||||
}
|
|
@ -277,6 +277,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_representation_type_bottom_test.dart'
|
||||
as extension_type_representation_type_bottom;
|
||||
import 'extension_type_with_abstract_member_test.dart'
|
||||
as extension_type_with_abstract_member;
|
||||
import 'external_field_constructor_initializer_test.dart'
|
||||
|
@ -1097,6 +1099,7 @@ main() {
|
|||
extension_type_implements_representation_not_supertype.main();
|
||||
extension_type_inherited_member_conflict.main();
|
||||
extension_type_representation_depends_on_itself.main();
|
||||
extension_type_representation_type_bottom.main();
|
||||
extension_type_with_abstract_member.main();
|
||||
external_field_constructor_initializer.main();
|
||||
external_field_initializer.main();
|
||||
|
|
|
@ -15,6 +15,8 @@ import "dart:async" show FutureOr;
|
|||
extension type V01(dynamic _) {}
|
||||
extension type V02(void _) {}
|
||||
extension type V03(Never _) {}
|
||||
// ^^^^^
|
||||
// [analyzer] COMPILE_TIME_ERROR.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM
|
||||
extension type V04(Null _) {}
|
||||
extension type V05(Function _) {}
|
||||
extension type V06(Record _) {}
|
||||
|
|
Loading…
Reference in a new issue