跳到主要内容

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);
}