//! returns: 0

/// Receiver for a method with function-local data.
record Source: Copy {
    /// Index into the method data.
    index: u32,
}

/// Read the first function's local data.
fn first(index: u32) -> u32 {
    constant VALUES: [u32; 3] = [11, 13, 17];
    return VALUES[index];
}

/// Read distinct local data with the same source name.
fn second(index: u32) -> u32 {
    constant VALUES: [u32; 3] = [19, 23, 29];
    return VALUES[index];
}

/// Read method-local data with the same source name.
fn (source: &Source) read() -> u32 {
    constant VALUES: [u32; 3] = [31, 37, 41];
    return VALUES[source.index];
}

/// Check registered data names through direct, indirect, and method calls.
@default fn main() -> u32 {
    let expected = [61 as u32, 73, 87];
    let readFirst = first;
    let readSecond = second;
    for index in 0..3 {
        let source = Source { index };
        assert first(index) + second(index) + source.read() == expected[index];
        assert readSecond(index) + readFirst(index) + source.read() == expected[index];
    }
    return 0;
}
