Skip to content

[inline]: a nested [inline] call taking a var struct parameter of the caller fails with 'local reference to non-local expression is unsafe' #11

Closed

Description

@lookibed

Summary

An [inline] function whose body binds a value with let and then calls another [inline] function with its var struct parameter fails to compile with error[31019]: local reference to non-local expression is unsafe when it is called from a function that received the struct as a parameter. The same call from a local variable compiles and runs. Nothing in the source is unsafe.

Reproducer

options gen2

struct Rt {
    pc : int = 0
    code : array<int>
    stack : array<int>
}

[inline]
def next_code(var rt : Rt) : int {
    let v = rt.code[rt.pc]
    rt.pc++
    return v
}

[inline]
def at(rt : Rt; i : int) : int {
    return rt.stack[i]
}

[inline]
def read(var rt : Rt) : int {
    let i = next_code(rt)
    return at(rt, i)
}

def op(var rt : Rt) : int {
    return read(rt)
}

[export]
def main() {
    var rt = Rt()
    push(rt.code, 1)
    push(rt.stack, 7)
    push(rt.stack, 9)
    print("{op(rt)}\n")
}

Observed / expected

variant result
as above error[31019]: local reference to non-local expression is unsafe at return at(rt, i)
read body as one expression return at(rt, next_code(rt)) same error
main calls read(rt) on its local rt instead of op(rt) prints 9
options disable_inline prints 9

Expected 9 in every variant.

Tested on 69a5896 (v0.6.4-481) and 388691e, interpreter, no project file.

Activity

  1. lookibed commented on Nov 9, 2026

    @lookibed
    OwnerAuthor

    Re-checked by the owner from this issue's reproducer on daScript abf1d40 (0.6.5): fixed upstream (GaijinEntertainment/daScript 2131620 GaijinEntertainment#4472 dasLLVM, 1404d5a GaijinEntertainment#4480 optimizer, f386f92 GaijinEntertainment#4482 cache and tools). The c2das-re probes were re-pinned in the repin PRs (lookibed/c2das-re#142-GaijinEntertainment#147; ruling 38 addendum 4).

  2. lookibed commented on Nov 9, 2026

    @lookibed
    OwnerAuthor

    Fixed upstream: GaijinEntertainment#4235 is closed and the fix is in master abf1d40e35 (0.6.5). Verified by running this issue's repro on a build of that commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions