address_position
'.address' 式は、リーフネイティブ外部呼び出しの引数としてのみ使用できます。
説明
#'.address' getter が、リーフ呼び出し (isLeaf: true) としてマークされたネイティブ外部呼び出しの引数以外のコンテキストで使用されている場合、アナライザーはこの診断を生成します。
例
#以下のコードは、.address が誤って使用されているため、この診断を生成します。
dart
import 'dart:ffi';
import 'dart:typed_data';
@Native<Void Function(Pointer<Uint8>)>()
external void nonLeafCall(Pointer<Uint8> ptr);
void main() {
final data = Uint8List(10);
// Incorrect: Using '.address' as an argument to a non-leaf call.
nonLeafCall(data.address);
}一般的な修正
#.address 式が、@Native(...) で注釈が付けられ、注釈に isLeaf: true が設定されているネイティブ外部呼び出しの引数として直接使用されていることを確認してください。
dart
import 'dart:ffi';
import 'dart:typed_data';
@Native<Void Function(Pointer<Uint8>)>(isLeaf: true)
external void leafCall(Pointer<Uint8> ptr);
void main() {
final data = Uint8List(10);
// Correct: Using .address directly as an argument to a leaf call.
leafCall(data.address);
}