Skip to content

fn test_* with an inferred return: check says ok, codegen fails with 'wrong argument type' (D43 entry-point tail rule) #1862

Closed

Description

@ehartford

fn test_* with an inferred return: with check says ok, codegen fails (or MIR is invalid)

Found while fixing #1855 (a runner helper named test_line_at returned str by inference).

Repro

fn test_label(k: i32): "a"

fn main:
    print("x " ++ test_label(0))
  • with check r.w → ok, exit 0
  • with run r.w →
    error: wrong argument type actual=i32 expected=ptr fn=main
    error: wrong argument type actual=str expected=ptr fn=main
    error: code generation failed
    
  • Inside src/main.w, the same shape made with check src/main.w report invalid MIR before codegen: call argument 0 is Unit but the callee parameter is not.

(v0.15.3.0-g355c20b16, darwin arm64.) Renaming the function to label compiles and prints x a.

Where

SemaCheck.fn_decl_is_entry_point (src/SemaCheck.w, D43): every function whose name starts with test_ has its tail in statement position, so test_label is inferred -> Unit (with analyze r.w 'select:stage=sema,kind=signature,name~test_label' shows the Unit return id). Sema then accepts the Unit result as an operand of ++ and as a call argument; codegen or the MIR validator is the first to notice.

Expected

Post-Sema invalid MIR is a compiler bug (D65). Either the use of the Unit result is a Sema type error with a diagnostic that names the D43 test_* rule, or the rule does not apply to a function that takes parameters (the runner cannot call it as a test: discover_test_functions in src/main.w lists any test_* function, parameters or not). Which of the two is the maintainer's call; with check saying ok is not.

Workaround used

The #1855 runner helper is named stdout_line_at.

Activity

  1. added
    bug
    on Sep 28, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    Fixed on main by 792351b (stack #2007, battery green on 0f13a62). A Unit operand of ++ or arithmetic is a Sema error naming the D43 test_* rule; trait contract returns are published before default bodies are checked.

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