Skip to content

Commit dc23738

Browse files
committed
v3: fix Linux alias regressions
1 parent c8d1965 commit dc23738

6 files changed

Lines changed: 33 additions & 7 deletions

File tree

vlib/v3/transform/expr.v

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -832,7 +832,8 @@ fn (mut t Transformer) transform_infix_struct_ops(_id flat.NodeId, node flat.Nod
832832
lhs_type = t.smartcast_target_type(sc)
833833
}
834834
}
835-
if lhs_type.len == 0 {
835+
if lhs_type.len == 0
836+
|| (t.generic_arg_is_unresolved(lhs_type) && !t.generic_arg_is_unresolved(checker_lhs_type)) {
836837
lhs_type = checker_lhs_type
837838
}
838839
lhs_node := t.a.nodes[int(lhs_id)]
@@ -1204,6 +1205,12 @@ fn (t &Transformer) raw_checker_node_type(id flat.NodeId) string {
12041205
}
12051206

12061207
fn (t &Transformer) raw_alias_type_for_expr(id flat.NodeId) string {
1208+
if raw_var_type := t.raw_var_type_for_expr(id) {
1209+
clean_var_type := t.trim_pointer_type(raw_var_type)
1210+
if t.is_type_alias_name(clean_var_type) {
1211+
return raw_var_type
1212+
}
1213+
}
12071214
raw_type := t.raw_checker_node_type(id)
12081215
if raw_type.len == 0 {
12091216
return ''
@@ -1213,6 +1220,17 @@ fn (t &Transformer) raw_alias_type_for_expr(id flat.NodeId) string {
12131220
if t.is_type_alias_name(clean) {
12141221
return raw_type
12151222
}
1223+
node := t.a.nodes[int(id)]
1224+
if node.kind == .infix && node.children_count > 0 {
1225+
lhs_id := t.a.child(&node, 0)
1226+
if lhs_type := t.raw_var_type_for_expr(lhs_id) {
1227+
clean_lhs_type := t.trim_pointer_type(lhs_type)
1228+
if t.is_type_alias_name(clean_lhs_type)
1229+
&& t.normalize_type_alias(clean_lhs_type) == t.normalize_type_alias(clean) {
1230+
return lhs_type
1231+
}
1232+
}
1233+
}
12161234
if is_ptr {
12171235
return ''
12181236
}

vlib/v3/transform/monomorphize.v

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9487,9 +9487,6 @@ fn (mut t Transformer) generic_comptime_typeof_target(node flat.Node, args []str
94879487
}
94889488
}
94899489
target := t.generic_comptime_base_type(child_id, args) or { return none }
9490-
if child.kind == .ident && t.mut_param_values[child.value] && !target.starts_with('&') {
9491-
return '&${target}'
9492-
}
94939490
return target
94949491
}
94959492

vlib/v3/transform/transform.v

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13365,6 +13365,12 @@ fn (mut t Transformer) transform_decl_assign_stmt(id flat.NodeId, node flat.Node
1336513365
} else if inferred := t.building_v_math_generic_call_type(rhs) {
1336613366
typ = inferred
1336713367
}
13368+
if t.generic_arg_is_unresolved(typ) {
13369+
checker_typ := t.checker_node_type(rhs_id)
13370+
if decl_type_is_usable(checker_typ) && !t.generic_arg_is_unresolved(checker_typ) {
13371+
typ = checker_typ
13372+
}
13373+
}
1336813374
}
1336913375
if rhs.kind == .call && t.is_strings_builder_new_call(rhs_id, rhs) {
1337013376
typ = 'strings.Builder'

vlib/v3/types/checker.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8281,7 +8281,9 @@ pub fn (mut tc TypeChecker) check_semantics() {
82818281
tc.check_pascal_case_name(node_id, node.value, type_kind, tc.declaration_keyword_name_pos(node_id,
82828282
'type'))
82838283
}
8284-
if tc.type_declaration_exists_before(node_id, node.value) {
8284+
is_c_alias := node.value.starts_with('C.') && node.children_count == 0
8285+
&& split_sum_variant_texts(node.typ).len <= 1
8286+
if !is_c_alias && tc.type_declaration_exists_before(node_id, node.value) {
82858287
kind := if node.children_count > 0
82868288
|| split_sum_variant_texts(node.typ).len > 1 {
82878289
'sum type'

vlib/v3/types/checker_comptime.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3595,7 +3595,7 @@ fn (mut tc TypeChecker) check_prefix_expr(id flat.NodeId, node flat.Node) {
35953595
}
35963596
if node.op == .amp && address_child.kind == .index && address_child.children_count > 0 {
35973597
base_id := tc.a.child(&address_child, 0)
3598-
base_type := unalias_and_unwrap_pointer_type(tc.resolve_type(base_id))
3598+
base_type := unwrap_pointer(tc.resolve_type(base_id))
35993599
if base_type is Map && tc.unsafe_depth == 0 && !tc.expr_is_inside_unsafe_block(id) {
36003600
tc.record_error_at(.assignment_mismatch,
36013601
'cannot take the address of map values outside `unsafe`', child_id,

vlib/v3/types/checker_parallel.v

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -987,7 +987,10 @@ fn (mut tc TypeChecker) check_top_level_declarations_filtered(do_values bool, do
987987
continue
988988
}
989989
node_id := flat.NodeId(i)
990-
if node.kind == .type_decl && tc.type_declaration_exists_before(node_id, node.value) {
990+
is_c_alias := node.kind == .type_decl && node.value.starts_with('C.')
991+
&& node.children_count == 0 && split_sum_variant_texts(node.typ).len <= 1
992+
if node.kind == .type_decl && !is_c_alias
993+
&& tc.type_declaration_exists_before(node_id, node.value) {
991994
kind := if node.children_count > 0 || split_sum_variant_texts(node.typ).len > 1 {
992995
'sum type'
993996
} else {

0 commit comments

Comments
 (0)