//! returns: 0
//! Test a record method and a trait method with eight declared parameters.
//!
//! The receiver is not a declared parameter, so each method has nine IL
//! arguments. The eighth declared parameter is passed on the stack.

record Scale: Copy {
    k: u32,
}

fn (s: &Scale) mix(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32, g: u32, h: u32) -> u32 {
    return (a + b * 2 + c * 3 + d * 4 + e * 5 + f * 6 + g * 7 + h * 8) * s.k;
}

trait Blender {
    fn (&Blender) blend(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32, g: u32, h: u32) -> u32;
}

instance Blender for Scale {
    fn (s: &Scale) blend(a: u32, b: u32, c: u32, d: u32, e: u32, f: u32, g: u32, h: u32) -> u32 {
        return (a + b * 2 + c * 3 + d * 4 + e * 5 + f * 6 + g * 7 + h * 8) * s.k;
    }
}

fn viaTrait(b: &opaque Blender) -> u32 {
    return b.blend(1, 2, 3, 4, 5, 6, 7, 8);
}

@default fn main() -> i32 {
    let s = Scale { k: 2 };

    // Direct method call. 1 + 4 + 9 + 16 + 25 + 36 + 49 + 64 = 204.
    if s.mix(1, 2, 3, 4, 5, 6, 7, 8) <> 408 {
        return 1;
    }
    // Argument order matters: the stack argument is the last one.
    if s.mix(8, 7, 6, 5, 4, 3, 2, 1) == 408 {
        return 2;
    }
    // Trait method call through a trait object.
    if viaTrait(&s) <> 408 {
        return 3;
    }
    let o: &opaque Blender = &s;
    if o.blend(8, 7, 6, 5, 4, 3, 2, 1) == 408 {
        return 4;
    }
    return 0;
}
