Docs for additional extension type diagnostics
I think these are the last of the diagnostics added for extension types.
Change-Id: I86744f8cab2683c5c6fb18a59e92a9c0ab7ff672
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338582
Reviewed-by: Marya Belanger <mbelanger@google.com>
Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
diff --git a/pkg/analyzer/messages.yaml b/pkg/analyzer/messages.yaml
index 01ee657..1cbab82 100644
--- a/pkg/analyzer/messages.yaml
+++ b/pkg/analyzer/messages.yaml
@@ -5596,6 +5596,30 @@
problemMessage: "The representation type can't be a bottom type."
correctionMessage: Try specifying a different type.
comment: No parameters.
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when the representation type of an
+ extension type is the [bottom type][] `Never`. The type `Never` can't be
+ the representation type of an extension type because there are no values
+ that can be extended.
+
+ #### Example
+
+ The following code produces this diagnostic because the representation
+ type of the extension type `E` is `Never`:
+
+ ```dart
+ extension type E([!Never!] n) {}
+ ```
+
+ #### Common fixes
+
+ Replace the extension type with a different type:
+
+ ```dart
+ extension type E(String s) {}
+ ```
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}'."
@@ -5603,6 +5627,41 @@
Parameters:
0: the name of the abstract method
1: the name of the enclosing extension type
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when an extension type declares an
+ abstract member. Because extension type member references are resolved
+ statically, an abstract member in an extension type could never be
+ executed.
+
+ #### Example
+
+ The following code produces this diagnostic because the method `m` in the
+ extension type `E` is abstract:
+
+ ```dart
+ extension type E(String s) {
+ [!void m();!]
+ }
+ ```
+
+ #### Common fixes
+
+ If the member is intended to be executable, then provide an implementation
+ of the member:
+
+ ```dart
+ extension type E(String s) {
+ void m() {}
+ }
+ ```
+
+ If the member isn't intended to be executable, then remove it:
+
+ ```dart
+ extension type E(String s) {}
+ ```
EXTERNAL_FIELD_CONSTRUCTOR_INITIALIZER:
sharedName: EXTERNAL_WITH_INITIALIZER
problemMessage: External fields can't have initializers.
@@ -15693,6 +15752,36 @@
SUPER_IN_EXTENSION_TYPE:
problemMessage: "The 'super' keyword can't be used in an extension type because an extension type doesn't have a superclass."
comment: No parameters.
+ documentation: |-
+ #### Description
+
+ The analyzer produces this diagnostic when `super` is used in an instance
+ member of an extension type. Extension types don't have superclasses, so
+ there's no inherited member that could be invoked.
+
+ #### Example
+
+ The following code produces this diagnostic because :
+
+ ```dart
+ extension type E(String s) {
+ void m() {
+ [!super!].m();
+ }
+ }
+ ```
+
+ #### Common fixes
+
+ Replace or remove the `super` invocation:
+
+ ```dart
+ extension type E(String s) {
+ void m() {
+ s.toLowerCase();
+ }
+ }
+ ```
SUPER_IN_INVALID_CONTEXT:
problemMessage: "Invalid context for 'super' invocation."
hasPublishedDocs: true
diff --git a/pkg/analyzer/tool/diagnostics/diagnostics.md b/pkg/analyzer/tool/diagnostics/diagnostics.md
index 5838fe4..1f340be 100644
--- a/pkg/analyzer/tool/diagnostics/diagnostics.md
+++ b/pkg/analyzer/tool/diagnostics/diagnostics.md
@@ -28,6 +28,7 @@
doesn't conform to the language specification or
that might work in unexpected ways.
+[bottom type]: https://dart.dev/null-safety/understanding-null-safety#top-and-bottom
[ffi]: https://dart.dev/guides/libraries/c-interop
[IEEE 754]: https://en.wikipedia.org/wiki/IEEE_754
[irrefutable pattern]: https://dart.dev/resources/glossary#irrefutable-pattern
@@ -6709,6 +6710,73 @@
extension type A(String s) {}
{% endprettify %}
+### extension_type_representation_type_bottom
+
+_The representation type can't be a bottom type._
+
+#### Description
+
+The analyzer produces this diagnostic when the representation type of an
+extension type is the [bottom type][] `Never`. The type `Never` can't be
+the representation type of an extension type because there are no values
+that can be extended.
+
+#### Example
+
+The following code produces this diagnostic because the representation
+type of the extension type `E` is `Never`:
+
+{% prettify dart tag=pre+code %}
+extension type E([!Never!] n) {}
+{% endprettify %}
+
+#### Common fixes
+
+Replace the extension type with a different type:
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {}
+{% endprettify %}
+
+### extension_type_with_abstract_member
+
+_'{0}' must have a method body because '{1}' is an extension type._
+
+#### Description
+
+The analyzer produces this diagnostic when an extension type declares an
+abstract member. Because extension type member references are resolved
+statically, an abstract member in an extension type could never be
+executed.
+
+#### Example
+
+The following code produces this diagnostic because the method `m` in the
+extension type `E` is abstract:
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {
+ [!void m();!]
+}
+{% endprettify %}
+
+#### Common fixes
+
+If the member is intended to be executable, then provide an implementation
+of the member:
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {
+ void m() {}
+}
+{% endprettify %}
+
+If the member isn't intended to be executable, then remove it:
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {}
+{% endprettify %}
+
### external_with_initializer
_External fields can't have initializers._
@@ -20009,6 +20077,41 @@
}
{% endprettify %}
+### super_in_extension_type
+
+_The 'super' keyword can't be used in an extension type because an extension
+type doesn't have a superclass._
+
+#### Description
+
+The analyzer produces this diagnostic when `super` is used in an instance
+member of an extension type. Extension types don't have superclasses, so
+there's no inherited member that could be invoked.
+
+#### Example
+
+The following code produces this diagnostic because :
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {
+ void m() {
+ [!super!].m();
+ }
+}
+{% endprettify %}
+
+#### Common fixes
+
+Replace or remove the `super` invocation:
+
+{% prettify dart tag=pre+code %}
+extension type E(String s) {
+ void m() {
+ s.toLowerCase();
+ }
+}
+{% endprettify %}
+
### super_in_invalid_context
_Invalid context for 'super' invocation._
diff --git a/pkg/analyzer/tool/diagnostics/generate.dart b/pkg/analyzer/tool/diagnostics/generate.dart
index a2d6373..dba0888 100644
--- a/pkg/analyzer/tool/diagnostics/generate.dart
+++ b/pkg/analyzer/tool/diagnostics/generate.dart
@@ -194,6 +194,7 @@
doesn't conform to the language specification or
that might work in unexpected ways.
+[bottom type]: https://dart.dev/null-safety/understanding-null-safety#top-and-bottom
[ffi]: https://dart.dev/guides/libraries/c-interop
[IEEE 754]: https://en.wikipedia.org/wiki/IEEE_754
[irrefutable pattern]: https://dart.dev/resources/glossary#irrefutable-pattern