Skip to content

Bug: Direct return of struct literal with embedded function calls fails to compile #409

Closed

Description

@godofecht

Description

Returning a struct literal directly from a function, where one or more fields are initialized with function calls, fails to compile. The compiler produces FLOW compilation failed with no further diagnostic.

Reproduction

export struct Foo {
    x: Matrix,
    y: ptr<f32>,
    n: i32
}

export function make_foo(X: Matrix, y: ptr<f32>) -> Foo {
    return Foo {
        x: matrix_copy(X),
        y: array_copy_f32(y, X.rows),
        n: X.rows
    }
}

This fails to compile.

Expected behavior

The struct literal should be constructed with the function call results and returned successfully.

Workaround

Assign each function call to a local variable first, then use those variables in the struct literal:

export function make_foo(X: Matrix, y: ptr<f32>) -> Foo {
    let x_copy: Matrix = matrix_copy(X)
    let y_copy: ptr<f32> = array_copy_f32(y, X.rows)
    let result: Foo = Foo {
        x: x_copy,
        y: y_copy,
        n: X.rows
    }
    return result
}

This compiles and works correctly.

Impact

Discovered in flow-scikit radius_neighbors_regressor_fit. The pattern of returning a struct literal with function calls is common and natural, so this limitation affects many use cases.

Activity

  1. added
    bug
    on Aug 11, 2026
  2. godofecht commented on Aug 11, 2026

    @godofecht
    ContributorAuthor

    Fixed in PR #419 (merged).

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

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions