Skip to content

Commit 13791e4

Browse files
scheglovCommit Queue
authored and
Commit Queue
committed
Extension type. Report when the representation type is a bottom type.
See dart-lang/language@3ecf3a7 Change-Id: If58e262fb913a11edd8f0ecf3f2dcba6879ee65b Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331086 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 5bed3cc commit 13791e4

File tree

9 files changed

+63
-0
lines changed

9 files changed

+63
-0
lines changed

pkg/analysis_server/lib/src/services/correction/error_fix_status.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,8 @@ CompileTimeErrorCode.EXTENSION_TYPE_INHERITED_MEMBER_CONFLICT:
683683
status: noFix
684684
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_DEPENDS_ON_ITSELF:
685685
status: noFix
686+
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM:
687+
status: noFix
686688
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER:
687689
status: needsFix
688690
notes: |-

pkg/analyzer/lib/src/error/codes.g.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1731,6 +1731,14 @@ class CompileTimeErrorCode extends AnalyzerErrorCode {
17311731
correctionMessage: "Try specifying a different type.",
17321732
);
17331733

1734+
/// No parameters.
1735+
static const CompileTimeErrorCode EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM =
1736+
CompileTimeErrorCode(
1737+
'EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM',
1738+
"The representation type can't be a bottom type.",
1739+
correctionMessage: "Try specifying a different type.",
1740+
);
1741+
17341742
/// Parameters:
17351743
/// 0: the name of the abstract method
17361744
/// 1: the name of the enclosing extension type

pkg/analyzer/lib/src/error/error_code_values.g.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ const List<ErrorCode> errorCodeValues = [
208208
CompileTimeErrorCode.EXTENSION_TYPE_IMPLEMENTS_REPRESENTATION_NOT_SUPERTYPE,
209209
CompileTimeErrorCode.EXTENSION_TYPE_INHERITED_MEMBER_CONFLICT,
210210
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_DEPENDS_ON_ITSELF,
211+
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM,
211212
CompileTimeErrorCode.EXTENSION_TYPE_WITH_ABSTRACT_MEMBER,
212213
CompileTimeErrorCode.EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER,
213214
CompileTimeErrorCode.EXTERNAL_FIELD_INITIALIZER,

pkg/analyzer/lib/src/generated/error_verifier.dart

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,7 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
714714
_checkForNonCovariantTypeParameterPositionInRepresentationType(
715715
node, element);
716716
_checkForExtensionTypeRepresentationDependsOnItself(node, element);
717+
_checkForExtensionTypeRepresentationTypeBottom(node, element);
717718
_checkForExtensionTypeImplementsDeferred(node);
718719
_checkForExtensionTypeImplementsItself(node, element);
719720
_checkForExtensionTypeMemberConflicts(
@@ -2965,6 +2966,19 @@ class ErrorVerifier extends RecursiveAstVisitor<void>
29652966
}
29662967
}
29672968

2969+
void _checkForExtensionTypeRepresentationTypeBottom(
2970+
ExtensionTypeDeclarationImpl node,
2971+
ExtensionTypeElementImpl element,
2972+
) {
2973+
final representationType = element.representation.type;
2974+
if (typeSystem.isBottom(representationType)) {
2975+
errorReporter.reportErrorForNode(
2976+
CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM,
2977+
node.representation.fieldType,
2978+
);
2979+
}
2980+
}
2981+
29682982
void _checkForExtensionTypeWithAbstractMember(
29692983
ExtensionTypeDeclarationImpl node,
29702984
) {

pkg/analyzer/messages.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5165,6 +5165,10 @@ CompileTimeErrorCode:
51655165
problemMessage: "The extension type representation can't depend on itself."
51665166
correctionMessage: Try specifying a different type.
51675167
comment: No parameters.
5168+
EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM:
5169+
problemMessage: "The representation type can't be a bottom type."
5170+
correctionMessage: Try specifying a different type.
5171+
comment: No parameters.
51685172
EXTENSION_TYPE_WITH_ABSTRACT_MEMBER:
51695173
problemMessage: "'{0}' must have a method body because '{1}' is an extension type."
51705174
correctionMessage: "Try adding a body to '{0}'."

pkg/analyzer/test/src/diagnostics/conflicting_generic_interfaces_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,8 @@ class B implements I<num> {}
224224
extension type C(Never it) implements A, B {}
225225
''', [
226226
error(CompileTimeErrorCode.CONFLICTING_GENERIC_INTERFACES, 87, 1),
227+
error(CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM, 89,
228+
5),
227229
]);
228230
}
229231

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'package:analyzer/src/error/codes.dart';
6+
import 'package:test_reflective_loader/test_reflective_loader.dart';
7+
8+
import '../dart/resolution/context_collection_resolution.dart';
9+
10+
main() {
11+
defineReflectiveSuite(() {
12+
defineReflectiveTests(ExtensionTypeRepresentationTypeBottomTest);
13+
});
14+
}
15+
16+
@reflectiveTest
17+
class ExtensionTypeRepresentationTypeBottomTest
18+
extends PubPackageResolutionTest {
19+
test_never() async {
20+
await assertErrorsInCode('''
21+
extension type A(Never it) {}
22+
''', [
23+
error(CompileTimeErrorCode.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM, 17,
24+
5),
25+
]);
26+
}
27+
}

pkg/analyzer/test/src/diagnostics/test_all.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,8 @@ import 'extension_type_inherited_member_conflict_test.dart'
277277
as extension_type_inherited_member_conflict;
278278
import 'extension_type_representation_depends_on_itself_test.dart'
279279
as extension_type_representation_depends_on_itself;
280+
import 'extension_type_representation_type_bottom_test.dart'
281+
as extension_type_representation_type_bottom;
280282
import 'extension_type_with_abstract_member_test.dart'
281283
as extension_type_with_abstract_member;
282284
import 'external_field_constructor_initializer_test.dart'
@@ -1097,6 +1099,7 @@ main() {
10971099
extension_type_implements_representation_not_supertype.main();
10981100
extension_type_inherited_member_conflict.main();
10991101
extension_type_representation_depends_on_itself.main();
1102+
extension_type_representation_type_bottom.main();
11001103
extension_type_with_abstract_member.main();
11011104
external_field_constructor_initializer.main();
11021105
external_field_initializer.main();

tests/language/extension_type/extension_type_representation_type_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import "dart:async" show FutureOr;
1515
extension type V01(dynamic _) {}
1616
extension type V02(void _) {}
1717
extension type V03(Never _) {}
18+
// ^^^^^
19+
// [analyzer] COMPILE_TIME_ERROR.EXTENSION_TYPE_REPRESENTATION_TYPE_BOTTOM
1820
extension type V04(Null _) {}
1921
extension type V05(Function _) {}
2022
extension type V06(Record _) {}

0 commit comments

Comments
 (0)