Skip to content

[cfe/ffi] Cascading error on wrong types when using .address #56462

Closed
@dcharkes

Description

@dcharkes

There is 2 errors being thrown for this snippet

@Native<Void Function(Pointer<Void>)>(isLeaf: true)
external void myNative(Pointer<Void> buffer);

void main() {
  final typedData = Int8List.fromList([1, 2]);
  myNative(typedData.address);
}

Output of dart <thisfile.dart>:

tests/ffi/static_checks/address_of_cast_test.dart:50:22: Error: The argument type 'Pointer<Int8>' can't be assigned to the parameter type 'Pointer<Void>'.
 - 'Pointer' is from 'dart:ffi'.
 - 'Int8' is from 'dart:ffi'.
 - 'Void' is from 'dart:ffi'.
  myNative(typedData.address);
                     ^
tests/ffi/static_checks/address_of_cast_test.dart:50:22: Error: The '.address' expression can only be used as argument to a leaf native external call.
  myNative(typedData.address);

The second error is not supposed to be thrown, and its not reported by analyzer (confirmed that by running dart analyze and got only one error which is the first one)

I tested this on 3.5.0-292.0.dev, seems this is a existing behavior.

Originally posted by @codesculpture in #55971 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-native-interopUsed for native interop related issues, including FFI.contributions-welcomeContributions welcome to help resolve this (the resolution is expected to be clear from the issue)library-ffi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions