opa: 'opa build -t wasm' with functions defined on entrypoint fails with "undefined ref"

Short description

Everything builds and tests pass. When attempting to build for WASM:

opa build -e "reproduction" -t wasm reproduction.rego
error: 1 error occurred: reproduction.rego:1: rego_type_error: undefined ref: data.reproduction.func_decide
        data.reproduction.func_decide
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        have: (any) => object<bool: boolean>

Problem observed on 0.38.0, 0.37.2

Steps To Reproduce

reproduction.rego

package reproduction

func_not(y) = {"bool":false} {
    y.bool
} else = {"bool":true}

func_decide(something) = func_not(something)

reproduction_test.rego

package reproduction

test_repro {
    func_decide({"bool":false}).bool
}

Expected behavior

Successful WASM build or test build failing or tests not passing.

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 15 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Regarding prioritization, while the pattern I shared above will not compile in a single package, we did manage to find a workaround and noticed that if we put the functions being composed in a separate package, then we can compose them. This has worked so far, and may work for now. My concern is with artificially breaking things out into packages instead of keeping code that goes together together.

I’m glad you’ve got a workaround; this still is something we should fix. I’d have to dig in a bit to understand the rationale behind the current way things are done 🔍

May I ask about your use case? I’m always curious about people using wasm 😅