Skip to content

Expand default arguments for method-style calls #736

Closed

Description

@LunaStev

Problem

Omitted default parameters are accepted for method-style calls but are not added to the emitted call. front/parser/src/generics.rs rewrites method arguments without the default expansion used for ordinary function calls; llvm/src/expression/rvalue/calls.rs then emits too few LLVM arguments.

Reproduction

Tested at 5002a93a4a233032553aa6c6e3639d88e93c53bf on Fedora Linux 43 amd64 with LLVM 21.1.8. Build the current compiler with LLVM_SYS_211_PREFIX=/usr/lib64/llvm21 cargo build --locked --release --jobs 2.

Save as repro.wave:

struct S {
    x: i32;
    fun value(self: S, extra: i32 = 2) -> i32 {
        return self.x + extra;
    }
}
fun main() -> i32 {
    var s: S = S { x: 3 };
    return s.value() - 5;
}
target/release/wavec check repro.wave
target/release/wavec build repro.wave -O0 --emit=ir,obj,bin --out-dir /tmp/wave-audit-repro

Repeat the build with -O2.

check succeeds. Both O0/O2 builds fail with E9002 and LLVM verification reports Incorrect number of arguments passed to called function! for call i32 @S_value(%S %load_s).

Writing s.value(2) builds and returns 0. Moving value to a free function reproduces the failure with method-style s.value(), while value(s) expands the default and returns 0. These controls were executed at O0/O2.

Scope

Apply the existing literal-default contract after resolving a method or free-function fallback. Keep receiver accounting, explicit arguments, generic specialization and source provenance consistent. Evaluate the receiver and each supplied argument once. No new default-expression syntax is required. Difficulty: medium.

Completion criteria

  • Direct methods and free-function fallback calls expand omitted defaults just as ordinary calls do.
  • Explicit/default argument combinations and invalid arity receive consistent checking and lowering.
  • O0/O2 regressions cover value/pointer receivers, scalar defaults and generic methods; receiver side effects occur once.

Activity

  1. added
    bug
    help wanted
    needs testing
    on Sep 25, 2026
  2. self-assigned this
    on Sep 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bughelp wantedneeds testing

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions