negative_ variable_ dimension
The variable dimension of a variable-length array must be non-negative.
Description
#The analyzer produces this diagnostic in two cases.
The first is when the variable dimension given in an
Array.variableWithVariableDimension
annotation is negative. The variable
dimension is the first argument in the annotation.
The second is when the variable dimension given in an
Array.variableMulti
annotation is negative. The variable dimension is
specified in the
variableDimension
argument of the annotation.
For more information about FFI, see C interop using dart:ffi.
Examples
#
The following code produces this diagnostic because a variable dimension
of
-1
was provided in the
Array.variableWithVariableDimension
annotation:
import 'dart:ffi';
final class MyStruct extends Struct {
@Array.variableWithVariableDimension(-1)
external Array<Uint8> a0;
}
The following code produces this diagnostic because a variable dimension
of
-1
was provided in the
Array.variableMulti
annotation:
import 'dart:ffi';
final class MyStruct2 extends Struct {
@Array.variableMulti(variableDimension: -1, [1, 2])
external Array<Array<Array<Uint8>>> a0;
}
Common fixes
#Change the variable dimension with zero (0
) or a positive number:
import 'dart:ffi';
final class MyStruct extends Struct {
@Array.variableWithVariableDimension(1)
external Array<Uint8> a0;
}
Change the variable dimension with zero (0
) or a positive number:
import 'dart:ffi';
final class MyStruct2 extends Struct {
@Array.variableMulti(variableDimension: 1, [1, 2])
external Array<Array<Array<Uint8>>> a0;
}
Unless stated otherwise, the documentation on this site reflects Dart 3.9.2. Page last updated on 2025-9-1. View source or report an issue.