refine distinct construction semantics
This commit is contained in:
@@ -3651,11 +3651,7 @@ ct_eval_call_expr :: proc(state: ^Ct_State, expr: ast.Expr, expected: types.Type
|
||||
if (builtin == .Size_Of || builtin == .Align_Of) && !valid_layout_type(checker, target) {
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_failf(state, .Not_Comptime, checker.ast_module.exprs[expr.args[0]].span, "layout target must be a sized runtime value type, got %s", type_label(checker, target))
|
||||
}
|
||||
bound_representation := target
|
||||
if backing, ok := types.distinct_scalar_backing(target, &checker.module.types); ok {
|
||||
bound_representation = backing
|
||||
}
|
||||
if (builtin == .Min_Value || builtin == .Max_Value) && !types.is_concrete_integer(bound_representation) {
|
||||
if (builtin == .Min_Value || builtin == .Max_Value) && !is_integer_bound_type(checker, target) {
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_failf(state, .Not_Comptime, checker.ast_module.exprs[expr.args[0]].span, "integer bound target must be a concrete integer type, got %s", type_label(checker, target))
|
||||
}
|
||||
result_type := types.USIZE if builtin == .Size_Of || builtin == .Align_Of else target
|
||||
@@ -3743,14 +3739,23 @@ ct_eval_call_expr :: proc(state: ^Ct_State, expr: ast.Expr, expected: types.Type
|
||||
return INVALID_CT_VALUE, flow, ok
|
||||
}
|
||||
actual := state.values[value].type
|
||||
if !types.can_retype_distinct(actual, target, &checker.module.types) {
|
||||
backing := types.resolve_alias(target_item.child, &checker.module.types)
|
||||
if types.is_concrete_scalar(backing) && !types.is_bool(backing) {
|
||||
value, flow, ok = ct_scalar_cast(state, value, backing, expr.span)
|
||||
if !ok || flow.kind != .Normal {
|
||||
return INVALID_CT_VALUE, flow, ok
|
||||
}
|
||||
actual = state.values[value].type
|
||||
}
|
||||
}
|
||||
if !types.can_retype_distinct(actual, target, &checker.module.types) {
|
||||
return INVALID_CT_VALUE, ct_flow(.Normal), ct_failf(
|
||||
state,
|
||||
.Not_Comptime,
|
||||
expr.span,
|
||||
"distinct type '%s' requires an exact %s value, got %s",
|
||||
"cannot construct distinct type '%s' from %s",
|
||||
symbol_text(checker, expr.name),
|
||||
types.name(target_item.child),
|
||||
types.name(actual),
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user