close
Skip to content

@:hlNative on extern function silently omits native registrations in HL target #12878

@rikzun

Description

@rikzun

Haxe version: latest (reproduced on 4.x)
Target: HashLink (hl)

Description

When using @:hlNative on an extern function inside a regular class, the compiler does not emit native function entries into the .hl bytecode. As a result, HashLink cannot resolve the functions at runtime and either crashes with JIT ERROR -1 or Failed to load function.

The same binding works correctly when the function has a stub body ({ return null; }) without the extern keyword.

Reproduction

Working:

class SysNative {
    @:hlNative("std", "sys_locale")
    static public function sysLocale(): hl.Bytes { return null; }
}

Not working (no compile-time error, runtime crash):

class SysNative {
    @:hlNative("std", "sys_locale")
    static extern public function sysLocale(): hl.Bytes;
}

Investigation

Comparing the two compiled .hl files shows that in the extern function variant, the native function name (sys_locale) is completely absent from the bytecode string table. The native entry is never written, so functions_indexes for that findex remains 0xFFFFFFFF, which triggers ASSERT(fid) in jit.c:1585 (op_call_fun).

Attempting to compile with --hl out.c also throws Invalid_argument("index out of bounds") for the extern variant, further confirming the issue is in the compiler emit phase.

Expected behavior

@:hlNative on an extern function should produce the same bytecode output as on a regular function with a stub body, consistent with how the feature works on other targets.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions