@@ -146,8 +146,9 @@ class _FfiDefinitionTransformer extends FfiTransformer {
146146 final sizeAnnotations = _getArraySizeAnnotations (f);
147147 if (sizeAnnotations.length == 1 ) {
148148 final singleElementType = arraySingleElementType (type);
149- if (isCompoundSubtype (singleElementType)) {
150- final clazz = (singleElementType as InterfaceType ).classNode;
149+ if (singleElementType is InterfaceType &&
150+ isCompoundSubtype (singleElementType)) {
151+ final clazz = singleElementType.classNode;
151152 dependencies.add (clazz);
152153 }
153154 }
@@ -403,24 +404,31 @@ class _FfiDefinitionTransformer extends FfiTransformer {
403404 final sizeAnnotations = _getArraySizeAnnotations (f);
404405 if (sizeAnnotations.length == 1 ) {
405406 final singleElementType = arraySingleElementType (type);
406- if (isCompoundSubtype (singleElementType)) {
407- final clazz = (singleElementType as InterfaceType ).classNode;
408- _checkPacking (node, packing, clazz, f);
409- }
410- final dimensions = sizeAnnotations.single;
411- if (arrayDimensions (type) != dimensions.length) {
412- diagnosticReporter.report (
413- templateFfiSizeAnnotationDimensions
414- .withArguments (f.name.text),
415- f.fileOffset,
416- f.name.text.length,
417- f.fileUri);
418- }
419- for (var dimension in dimensions) {
420- if (dimension < 0 ) {
421- diagnosticReporter.report (messageNonPositiveArrayDimensions,
422- f.fileOffset, f.name.text.length, f.fileUri);
423- success = false ;
407+ if (singleElementType is ! InterfaceType ) {
408+ assert (singleElementType is InvalidType );
409+ // This class is invalid, but continue reporting other errors on it.
410+ // An error on the type will already have been reported.
411+ success = false ;
412+ } else {
413+ if (isCompoundSubtype (singleElementType)) {
414+ final clazz = singleElementType.classNode;
415+ _checkPacking (node, packing, clazz, f);
416+ }
417+ final dimensions = sizeAnnotations.single;
418+ if (arrayDimensions (type) != dimensions.length) {
419+ diagnosticReporter.report (
420+ templateFfiSizeAnnotationDimensions
421+ .withArguments (f.name.text),
422+ f.fileOffset,
423+ f.name.text.length,
424+ f.fileUri);
425+ }
426+ for (var dimension in dimensions) {
427+ if (dimension < 0 ) {
428+ diagnosticReporter.report (messageNonPositiveArrayDimensions,
429+ f.fileOffset, f.name.text.length, f.fileUri);
430+ success = false ;
431+ }
424432 }
425433 }
426434 } else {
@@ -568,8 +576,15 @@ class _FfiDefinitionTransformer extends FfiTransformer {
568576 if (sizeAnnotations.length == 1 ) {
569577 final arrayDimensions = sizeAnnotations.single;
570578 if (this .arrayDimensions (dartType) == arrayDimensions.length) {
571- type = NativeTypeCfe (this , dartType,
572- compoundCache: compoundCache, arrayDimensions: arrayDimensions);
579+ final elementType = arraySingleElementType (dartType);
580+ if (elementType is ! InterfaceType ) {
581+ assert (elementType is InvalidType );
582+ type = InvalidNativeTypeCfe ("Invalid element type." );
583+ } else {
584+ type = NativeTypeCfe (this , dartType,
585+ compoundCache: compoundCache,
586+ arrayDimensions: arrayDimensions);
587+ }
573588 } else {
574589 type = InvalidNativeTypeCfe ("Invalid array dimensions." );
575590 }
0 commit comments