@@ -9,6 +9,7 @@ import 'dart:math' as math;
99import 'package:front_end/src/api_unstable/vm.dart'
1010 show
1111 messageFfiPackedAnnotationAlignment,
12+ messageNonPositiveArrayDimensions,
1213 templateFfiEmptyStruct,
1314 templateFfiFieldAnnotation,
1415 templateFfiFieldNull,
@@ -323,14 +324,24 @@ class _FfiDefinitionTransformer extends FfiTransformer {
323324 compoundClassDependencies[node].add (clazz);
324325 _checkPacking (node, packing, clazz, f);
325326 }
326- if (arrayDimensions (type) != sizeAnnotations.single.length) {
327+ final dimensions = sizeAnnotations.single;
328+ if (arrayDimensions (type) != dimensions.length) {
327329 diagnosticReporter.report (
328330 templateFfiSizeAnnotationDimensions
329331 .withArguments (f.name.text),
330332 f.fileOffset,
331333 f.name.text.length,
332334 f.fileUri);
333335 }
336+ for (var dimension in dimensions) {
337+ if (dimension < 0 ) {
338+ diagnosticReporter.report (
339+ messageNonPositiveArrayDimensions, f.fileOffset,
340+ f.name.text.length,
341+ f.fileUri);
342+ success = false ;
343+ }
344+ }
334345 } else {
335346 diagnosticReporter.report (
336347 templateFfiSizeAnnotation.withArguments (f.name.text),
@@ -478,8 +489,8 @@ class _FfiDefinitionTransformer extends FfiTransformer {
478489 final sizeAnnotations = _getArraySizeAnnotations (m).toList ();
479490 if (sizeAnnotations.length == 1 ) {
480491 final arrayDimensions = sizeAnnotations.single;
481- type = NativeTypeCfe (this , dartType,
482- compoundCache : compoundCache, arrayDimensions: arrayDimensions);
492+ type = NativeTypeCfe (this , dartType, compoundCache : compoundCache,
493+ arrayDimensions: arrayDimensions);
483494 }
484495 } else if (isPointerType (dartType) || isCompoundSubtype (dartType)) {
485496 type = NativeTypeCfe (this , dartType, compoundCache: compoundCache);
@@ -749,7 +760,7 @@ class CompoundLayout {
749760abstract class NativeTypeCfe {
750761 factory NativeTypeCfe (FfiTransformer transformer, DartType dartType,
751762 {List <int > arrayDimensions,
752- Map <Class , CompoundNativeTypeCfe > compoundCache = const {}}) {
763+ Map <Class , CompoundNativeTypeCfe > compoundCache = const {}}) {
753764 if (transformer.isPrimitiveType (dartType)) {
754765 final clazz = (dartType as InterfaceType ).classNode;
755766 final nativeType = transformer.getType (clazz);
@@ -772,7 +783,7 @@ abstract class NativeTypeCfe {
772783 }
773784 final elementType = transformer.arraySingleElementType (dartType);
774785 final elementCfeType =
775- NativeTypeCfe (transformer, elementType, compoundCache: compoundCache);
786+ NativeTypeCfe (transformer, elementType, compoundCache: compoundCache);
776787 return ArrayNativeTypeCfe .multi (elementCfeType, arrayDimensions);
777788 }
778789 throw "Invalid type $dartType " ;
@@ -1135,8 +1146,8 @@ class ArrayNativeTypeCfe implements NativeTypeCfe {
11351146
11361147 ArrayNativeTypeCfe (this .elementType, this .length);
11371148
1138- factory ArrayNativeTypeCfe .multi (
1139- NativeTypeCfe elementType, List <int > dimensions) {
1149+ factory ArrayNativeTypeCfe .multi (NativeTypeCfe elementType,
1150+ List <int > dimensions) {
11401151 if (dimensions.length == 1 ) {
11411152 return ArrayNativeTypeCfe (elementType, dimensions.single);
11421153 }
0 commit comments