You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Correct: Using .address directly as an argument to a leaf call.
18998
+
leafCall(data.address);
18999
+
}
19000
+
```
18954
19001
ADDRESS_RECEIVER:
18955
19002
problemMessage: "The receiver of '.address' must be a concrete 'TypedData', a concrete 'TypedData' '[]', an 'Array', an 'Array' '[]', a Struct field, or a Union field."
18956
19003
correctionMessage: Change the receiver of '.address' to one of the allowed kinds.
18957
19004
hasPublishedDocs: false
18958
19005
comment: No parameters.
19006
+
documentation: |-
19007
+
#### Description
19008
+
19009
+
The analyzer produces this diagnostic when the `.address` getter is used
19010
+
on a receiver whose static type isn't one of the allowed FFI types. The
19011
+
`.address` getter is used to obtain a `Pointer` to the underlying memory
19012
+
of an FFI data structure.
19013
+
19014
+
The receiver of `.address` must be one of the following:
19015
+
- A concrete `TypedData` instance (e.g., `Uint8List`).
19016
+
- An element of a concrete `TypedData` instance accessed via `[]`.
19017
+
- An `Array<T>` instance (from `dart:ffi`).
19018
+
- An element of an `Array<T>` instance accessed via `[]`.
19019
+
- A field of a `Struct` or `Union` subclass, if that field's type is `Array<T>`, a nested `Struct`, or a nested `Union`.
19020
+
- A `Struct` or `Union` instance.
19021
+
19022
+
#### Example
19023
+
19024
+
The following code produces this diagnostic for various incorrect receivers:
19025
+
19026
+
```dart
19027
+
import 'dart:ffi';
19028
+
19029
+
final class MyStruct extends Struct {
19030
+
@Uint8()
19031
+
external int x;
19032
+
19033
+
@Uint8()
19034
+
external int y;
19035
+
}
19036
+
19037
+
@Native<Void Function(Pointer)>(isLeaf: true)
19038
+
external void nativeLeafCall(Pointer ptr);
19039
+
19040
+
void main() {
19041
+
final struct = Struct.create<MyStruct>();
19042
+
final y = struct.y;
19043
+
// Incorrect: The receiver is not a struct field, but some integer.
19044
+
nativeLeafCall(y.[!address!]);
19045
+
}
19046
+
```
19047
+
19048
+
#### Common fixes
19049
+
19050
+
Ensure that the receiver of the `.address` getter is one of the allowed
19051
+
types. The `.address` getter is for obtaining a `Pointer` to the memory
19052
+
of `TypedData`, `Array`, `Struct`, or `Union` instances, or certain
19053
+
fields/elements thereof.
19054
+
19055
+
```dart
19056
+
import 'dart:ffi';
19057
+
19058
+
@Native<Void Function(Pointer)>(isLeaf: true)
19059
+
external void nativeLeafCall(Pointer ptr);
19060
+
19061
+
final class MyStruct extends Struct {
19062
+
@Uint8()
19063
+
external int x;
19064
+
19065
+
@Uint8()
19066
+
external int y;
19067
+
}
19068
+
19069
+
void main() {
19070
+
final struct = Struct.create<MyStruct>();
19071
+
// Correct: The receiver is a struct field.
19072
+
nativeLeafCall(struct.y.address);
19073
+
}
19074
+
```
18959
19075
ANNOTATION_ON_POINTER_FIELD:
18960
19076
problemMessage: "Fields in a struct class whose type is 'Pointer' shouldn't have any annotations."
18961
19077
correctionMessage: Try removing the annotation.
@@ -19604,6 +19720,57 @@ FfiCode:
19604
19720
correctionMessage: Pass as Handle instead.
19605
19721
hasPublishedDocs: false
19606
19722
comment: No parameters.
19723
+
documentation: |-
19724
+
#### Description
19725
+
19726
+
The analyzer produces this diagnostic when a function or method annotated
19727
+
with `@Native` has a parameter in its FFI signature that is a `Pointer`,
19728
+
but the corresponding Dart parameter type is a class instance that doesn't
19729
+
extend `NativeFieldWrapperClass1` (or is a Pointer or TypedData).
19730
+
19731
+
#### Example
19732
+
19733
+
The following code produces this diagnostic because `MyService` doesn't
19734
+
extend `NativeFieldWrapperClass1`, but the `@Native` signature for its
19735
+
`process` method indicates the receiver should be passed as a `Pointer<Void>`:
19736
+
19737
+
```dart
19738
+
import 'dart:ffi';
19739
+
19740
+
class MyService { // MyService does not extend NativeFieldWrapperClass1
0 commit comments