Skip to content

[vm/ffi] Allow omitting @Native type if it can be inferred from the Dart signature #54810

Closed
@dcharkes

Description

@dcharkes

On struct fields, we don't require annotating the native types if they are identical to the Dart type. This is true for Pointer, and subtypes of Struct and Union. In the context of function types Void is also non-ambigious.

As @mkustermann suggested in #54739 (comment), we should consider making the type argument for @Native external functions omittable if it is pinned down by the Dart type:

@Native(isLeaf: true)
external void myFunc(Pointer<Int8>);

The only valid signature for this would be:

@Native<Void Function(Pointer<Int8>)>(isLeaf: true)
external void myFunc(Pointer<Int8>);

Which does not add any extra info.

And in contrast to the DynamicLibrary API, we also won't have a Pointer<NativeFunction<Void Function(Pointer<Int8>)>> type in our program that we would type check against.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.legacy-area-analyzerUse area-devexp instead.library-ffitriagedIssue has been triaged by sub teamtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions