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;
}
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。