Fix structural array element assignment

3c0dd6ed13523f80c57006fc2e0b58907392ea76e8ca0f52e2c1d594cb44efa7
Array assignment compatibility compared interned element-type pointers
instead of structural types. Independently allocated but equivalent
descriptors, such as identical function signatures in separate
annotations, were rejected while printing the same expected and actual
type.

Use the resolver's recursive `typesEqual` check for array element
compatibility.
Alexis Sellier committed ago 1 parent 6cdb3213
lib/std/lang/resolver.rad +1 -2
1700 1700
                }
1701 1701
                case ast::NodeValue::ArrayRepeatLit(repeat) => {
1702 1702
                    return isAssignable(self, *lhs.item, *rhs.item, repeat.item);
1703 1703
                }
1704 1704
                else => {
1705 -
                    // For non-literal arrays, require exact element type match.
1706 -
                    if lhs.item == rhs.item {
1705 +
                    if typesEqual(*lhs.item, *rhs.item) {
1707 1706
                        return Coercion::Identity;
1708 1707
                    }
1709 1708
                    return nil;
1710 1709
                }
1711 1710
            }
test/tests/array.fn.assign.rad added +13 -0
1 +
//! returns: 7
2 +
//! Structurally identical function array types assign across declarations.
3 +
4 +
fn seven() -> i32 {
5 +
    return 7;
6 +
}
7 +
8 +
@default fn main() -> i32 {
9 +
    let funcs: [fn() -> i32; 1] = [seven];
10 +
    let copy: [fn() -> i32; 1] = funcs;
11 +
12 +
    return copy[0]();
13 +
}