dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.22k stars 1.57k forks source link

[ffi] Misleading error messages when defining `@Native` annotated function-typed field #54042

Open mosuem opened 11 months ago

mosuem commented 11 months ago

When defining a method wrongly as such:

@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(symbol: 'symbol_name')
external static ffi.Pointer<ffi.Opaque> Function() _symbol_name;

The error messages complain about the number of arguments, not about the wrong type: Unexpected number of FfiNative annotation parameters. Expected x but has y. The correct syntax for that example would be

@ffi.Native<ffi.Pointer<ffi.Opaque> Function()>(symbol: 'symbol_name')
external static ffi.Pointer<ffi.Opaque> _symbol_name();

If the error messages could point users that way, that would be great.

dcharkes commented 11 months ago

Right, that's not a syntax that is supported by the FFI implementation.

It should give a proper error message.

NoSuchMethodError: The method 'call' was called on null.

And definitely not compile to a non-external function-typed field that has a null value.

dcharkes commented 11 months ago

Likely to be fixed at:

https://github.com/dart-lang/sdk/blob/0a20707e3f1084b85bcdcfb4035bdd150b90756f/pkg/vm/lib/transformations/ffi/native.dart#L710

a-siva commented 9 months ago

@dcharkes is P2 the right priority for this issue?