Skip to content

Commit 12f7507

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Improve the message for empty_struct
Change-Id: I17b1fb652234016bbdb94f7c813e24ea8890cd85 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/216120 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 50fb0c6 commit 12f7507

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,14 @@ class FfiCode extends AnalyzerErrorCode {
4646

4747
/**
4848
* Parameters:
49-
* 0: the name of the struct class
49+
* 0: the name of the subclass
50+
* 1: the name of the superclass
5051
*/
5152
static const FfiCode EMPTY_STRUCT = FfiCode(
5253
'EMPTY_STRUCT',
53-
"Struct '{0}' is empty. Empty structs are undefined behavior.",
54-
correctionMessage: "Try adding a field to '{0}' or use a different Struct.",
54+
"The class '{0}' can’t be empty because it's a subclass of '{1}'.",
55+
correctionMessage:
56+
"Try adding a field to '{0}' or use a different superclass.",
5557
);
5658

5759
/**

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
7878
compound = node;
7979
if (node.declaredElement!.isEmptyStruct) {
8080
_errorReporter.reportErrorForNode(
81-
FfiCode.EMPTY_STRUCT, node.name, [node.name.name]);
81+
FfiCode.EMPTY_STRUCT, node.name, [node.name.name, className]);
8282
}
8383
if (className == _structClassName) {
8484
_validatePackedAnnotation(node.metadata);
@@ -722,10 +722,10 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
722722
} else if (declaredType.isCompoundSubtype) {
723723
final clazz = (declaredType as InterfaceType).element;
724724
if (clazz.isEmptyStruct) {
725-
// TODO(brianwilkerson) There are no tests for this branch. Ensure
726-
// that the diagnostic is correct and add tests.
727-
_errorReporter
728-
.reportErrorForNode(FfiCode.EMPTY_STRUCT, node, [clazz.name]);
725+
_errorReporter.reportErrorForNode(FfiCode.EMPTY_STRUCT, node, [
726+
clazz.name,
727+
clazz.supertype!.getDisplayString(withNullability: false)
728+
]);
729729
}
730730
_validatePackingNesting(compound!.declaredElement!, clazz,
731731
errorNode: fieldType);

pkg/analyzer/messages.yaml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13746,11 +13746,12 @@ FfiCode:
1374613746
correctionMessage: "Try allocating it via allocation, or load from a 'Pointer'."
1374713747
comment: No parameters.
1374813748
EMPTY_STRUCT:
13749-
problemMessage: "Struct '{0}' is empty. Empty structs are undefined behavior."
13750-
correctionMessage: "Try adding a field to '{0}' or use a different Struct."
13749+
problemMessage: "The class '{0}' can’t be empty because it's a subclass of '{1}'."
13750+
correctionMessage: "Try adding a field to '{0}' or use a different superclass."
1375113751
comment: |-
1375213752
Parameters:
13753-
0: the name of the struct class
13753+
0: the name of the subclass
13754+
1: the name of the superclass
1375413755
EXTRA_ANNOTATION_ON_STRUCT_FIELD:
1375513756
problemMessage: Fields in a struct class must have exactly one annotation indicating the native type.
1375613757
correctionMessage: Try removing the extra annotation.

0 commit comments

Comments
 (0)