~sircmpwn/harec

c8c81f396ca9dc89cbcd35849dc727a98030f5b0 — Lassi Pulkkinen 1 year, 5 months ago 1c6ef7a
check: Only skip lower_implicit_cast(slice, expandable array) in slice assignments

This caused unexpected source/destination type mismatches
in such cases as:

let x: []u8 = [1, 2, 3...];

In reality this should produce an error, but now the behavior is at
least consistent with other similar cases -- the expansion is ignored.

Signed-off-by: Lassi Pulkkinen <lassi@pulk.fi>
1 files changed, 8 insertions(+), 7 deletions(-)

M src/check.c
M src/check.c => src/check.c +8 -7
@@ 146,12 146,6 @@ lower_implicit_cast(struct context *ctx,
	if (to == expr->result || expr->result->storage == STORAGE_NEVER) {
		return expr;
	}
	
	if (type_dealias(ctx, to)->storage == STORAGE_SLICE &&
		expr->result->storage == STORAGE_ARRAY &&
		expr->result->array.expandable) {
		return expr;
	}

	if (type_dealias(ctx, to)->storage == STORAGE_TAGGED) {
		const struct type *interim =


@@ 874,7 868,14 @@ check_expr_assign(struct context *ctx,
		check_binarithm_op(ctx, object, expr->assign.op);
	}

	expr->assign.value = lower_implicit_cast(ctx, object->result, value);
	if (object->type == EXPR_SLICE
			&& value->result->storage == STORAGE_ARRAY
			&& value->result->array.expandable) {
		expr->assign.value = value;
	} else {
		expr->assign.value =
			lower_implicit_cast(ctx, object->result, value);
	}
	expr->assign.object = object;
}