address_position
'.address' 表示式只能用作葉節點本地外部呼叫 (leaf native external call) 的引數。
描述
#當 .address getter 用於除標記為葉節點呼叫 (leaf call) (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);
}