Skip to content

'Pointer<NativeFunction<T Function()>> ptr; T Function() func = ptr.asFunction(); ' When T must be 'Pointer' to pass compilation checking. #54467

@SilverFruity

Description

@SilverFruity
  • Dart analyzer and linter

Test on dartpad

image

Test on The latest main branch

Executing this code with dart compiled from the latest commit on the main branch of the github repository has the same problem, as follows:

➜  sdk git:(main) ✗ PAGER=cat git log -1
commit f860d84ad77fa0910ae5be18e2211ac06119cf8a (HEAD -> main, origin/master, origin/main, origin/lkgr, origin/base, origin/HEAD)
Author: Nicholas Shahan <[email protected]>
Date:   Thu Dec 28 03:19:30 2023 +0000

    [test] Use Uris in place of Strings in test
    
    Provides consistent behavior for identical and equals across all
    backends. The test was failing on JavaScript backends because
    Strings that are equal are also identical.
    
    Change-Id: I85929f37746d8f7e192410e3d2f6530ce05176c5
    Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/343860
    Reviewed-by: Nate Bosch <[email protected]>
    Auto-Submit: Nicholas Shahan <[email protected]>
    Commit-Queue: Nate Bosch <[email protected]>
➜  sdk git:(main) ✗ ./tools/build.py --no-goma --mode release --arch x64 create_sdk
Generating Xcode projects took 47ms
Done. Made 428 targets from 121 files in 1574ms
buildtools/ninja/ninja -C xcodebuild/ReleaseX64 create_sdk
ninja: Entering directory `xcodebuild/ReleaseX64'
ninja: no work to do.
The build took 2.026 seconds
➜  sdk git:(main) ✗ cat test.dart
import "dart:ffi";

void main() {
   Pointer<NativeFunction<Pointer<Void> Function()>> isAlive = Pointer<NativeFunction<Pointer<Void> Function()>>.fromAddress(0x100000);
   Pointer<Void> Function() isAliveFunc = isAlive.asFunction();

   Pointer<NativeFunction<Void Function()>> isAlive1 = Pointer<NativeFunction<Void Function()>>.fromAddress(0x100000);
   Void Function() isAliveFunc1 = isAlive1.asFunction();
}
➜  sdk git:(main) ✗ ./xcodebuild/ReleaseX64/dart-sdk/bin/dart test.dart            
test.dart:8:44: Error: Expected type 'Void Function()' to be 'void Function()', which is the Dart type corresponding to 'NativeFunction<Void Function()>'.
 - 'Void' is from 'dart:ffi'.
 - 'NativeFunction' is from 'dart:ffi'.
   Void Function() isAliveFunc1 = isAlive1.asFunction();
                                           ^
➜  sdk git:(main) ✗ 

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.library-ffitriagedIssue has been triaged by sub team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions