Skip to content

Commit 88229cc

Browse files
committed
ci: fix v2 tests
1 parent 92d0e82 commit 88229cc

4 files changed

Lines changed: 51 additions & 32 deletions

File tree

vlib/v2/markused/markused_test.v

Lines changed: 29 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,16 @@
11
module markused
22

33
import v2.ast
4+
import v2.token
45
import v2.types
56

7+
fn pos(id int) token.Pos {
8+
return token.Pos{
9+
offset: id
10+
id: id
11+
}
12+
}
13+
614
fn test_mark_used_tracks_transitive_function_calls() {
715
mut env := types.Environment.new()
816
files := [
@@ -13,44 +21,44 @@ fn test_mark_used_tracks_transitive_function_calls() {
1321
ast.Stmt(ast.FnDecl{
1422
name: 'main'
1523
typ: ast.FnType{}
16-
pos: 1
24+
pos: pos(1)
1725
stmts: [
1826
ast.Stmt(ast.ExprStmt{
1927
expr: ast.CallExpr{
2028
lhs: ast.Ident{
2129
name: 'foo'
22-
pos: 2
30+
pos: pos(2)
2331
}
24-
pos: 2
32+
pos: pos(2)
2533
}
2634
}),
2735
]
2836
}),
2937
ast.Stmt(ast.FnDecl{
3038
name: 'foo'
3139
typ: ast.FnType{}
32-
pos: 3
40+
pos: pos(3)
3341
stmts: [
3442
ast.Stmt(ast.ExprStmt{
3543
expr: ast.CallExpr{
3644
lhs: ast.Ident{
3745
name: 'bar'
38-
pos: 4
46+
pos: pos(4)
3947
}
40-
pos: 4
48+
pos: pos(4)
4149
}
4250
}),
4351
]
4452
}),
4553
ast.Stmt(ast.FnDecl{
4654
name: 'bar'
4755
typ: ast.FnType{}
48-
pos: 5
56+
pos: pos(5)
4957
}),
5058
ast.Stmt(ast.FnDecl{
5159
name: 'dead'
5260
typ: ast.FnType{}
53-
pos: 6
61+
pos: pos(6)
5462
}),
5563
]
5664
},
@@ -79,22 +87,22 @@ fn test_mark_used_tracks_method_calls_with_env_types() {
7987
ast.Stmt(ast.FnDecl{
8088
name: 'main'
8189
typ: ast.FnType{}
82-
pos: 10
90+
pos: pos(10)
8391
stmts: [
8492
ast.Stmt(ast.ExprStmt{
8593
expr: ast.CallExpr{
8694
lhs: ast.SelectorExpr{
8795
lhs: ast.Ident{
8896
name: 'w'
89-
pos: 12
97+
pos: pos(12)
9098
}
9199
rhs: ast.Ident{
92100
name: 'ping'
93-
pos: 13
101+
pos: pos(13)
94102
}
95-
pos: 13
103+
pos: pos(13)
96104
}
97-
pos: 13
105+
pos: pos(13)
98106
}
99107
}),
100108
]
@@ -105,27 +113,27 @@ fn test_mark_used_tracks_method_calls_with_env_types() {
105113
name: 'w'
106114
typ: ast.Ident{
107115
name: 'Widget'
108-
pos: 14
116+
pos: pos(14)
109117
}
110-
pos: 14
118+
pos: pos(14)
111119
}
112120
name: 'ping'
113121
typ: ast.FnType{}
114-
pos: 15
122+
pos: pos(15)
115123
}),
116124
ast.Stmt(ast.FnDecl{
117125
is_method: true
118126
receiver: ast.Parameter{
119127
name: 'w'
120128
typ: ast.Ident{
121129
name: 'Widget'
122-
pos: 16
130+
pos: pos(16)
123131
}
124-
pos: 16
132+
pos: pos(16)
125133
}
126134
name: 'unused'
127135
typ: ast.FnType{}
128-
pos: 17
136+
pos: pos(17)
129137
}),
130138
]
131139
},
@@ -149,12 +157,12 @@ fn test_mark_used_keeps_all_functions_when_no_entry_root_exists() {
149157
ast.Stmt(ast.FnDecl{
150158
name: 'a'
151159
typ: ast.FnType{}
152-
pos: 21
160+
pos: pos(21)
153161
}),
154162
ast.Stmt(ast.FnDecl{
155163
name: 'b'
156164
typ: ast.FnType{}
157-
pos: 22
165+
pos: pos(22)
158166
}),
159167
]
160168
},

vlib/v2/transformer/transformer.v

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,12 @@ fn (t &Transformer) is_interface_var(name string) bool {
872872
// get_var_type_name returns the type name of a variable from scope lookup
873873
fn (t &Transformer) get_var_type_name(name string) string {
874874
typ := t.lookup_var_type(name) or { return '' }
875+
if typ is types.Alias {
876+
if typ.name != '' {
877+
return typ.name
878+
}
879+
return t.type_to_name(typ.base_type)
880+
}
875881
if typ is types.String {
876882
return 'string'
877883
}
@@ -6180,7 +6186,11 @@ fn (mut t Transformer) transform_index_expr(expr ast.IndexExpr) ast.Expr {
61806186

61816187
// Lower map reads `m[key]` to `map__get(&m, &key, &zero)` in transformer so backends
61826188
// do not need map-specific IndexExpr logic.
6183-
if map_expr_typ := t.get_expr_type(expr.lhs) {
6189+
mut map_expr_type_opt := t.get_expr_type(expr.lhs)
6190+
if map_expr_type_opt == none && expr.lhs is ast.Ident {
6191+
map_expr_type_opt = t.lookup_var_type((expr.lhs as ast.Ident).name)
6192+
}
6193+
if map_expr_typ := map_expr_type_opt {
61846194
if map_type := t.unwrap_map_type(map_expr_typ) {
61856195
synth_pos := t.next_synth_pos()
61866196

@@ -9543,8 +9553,8 @@ fn (t &Transformer) infer_variant_type(value ast.Expr, variants []string) string
95439553
}
95449554
}
95459555
// Prefer checker-provided types for match/smartcast narrowing.
9546-
if value.pos > 0 {
9547-
if typ := t.env.get_expr_type(value.pos) {
9556+
if value.pos.is_valid() {
9557+
if typ := t.env.get_expr_type(value.pos.id) {
95489558
matched2 := match_sumtype_variant_name(t.type_to_c_name(typ), variants)
95499559
if matched2 != '' {
95509560
return matched2
@@ -10873,15 +10883,16 @@ fn (mut t Transformer) empty_struct_arg_expr(param_type types.Type) ast.Expr {
1087310883
if t.is_pointer_type(param_type) {
1087410884
mut cur := param_type
1087510885
for cur is types.Alias {
10876-
cur = cur.base_type
10886+
cur = cur.base_type()
1087710887
}
1087810888
if cur is types.Pointer {
10889+
ptr := cur as types.Pointer
1087910890
init_pos := t.next_synth_pos()
1088010891
ptr_pos := t.next_synth_pos()
10881-
t.register_synth_type(init_pos, cur.base_type)
10892+
t.register_synth_type(init_pos, ptr.base_type)
1088210893
t.register_synth_type(ptr_pos, param_type)
1088310894
init_expr := ast.Expr(ast.InitExpr{
10884-
typ: t.type_to_ast_type_expr(cur.base_type)
10895+
typ: t.type_to_ast_type_expr(ptr.base_type)
1088510896
pos: init_pos
1088610897
})
1088710898
return ast.Expr(ast.PrefixExpr{
@@ -11036,10 +11047,11 @@ fn (mut t Transformer) lower_struct_shorthand_call(args []ast.Expr, param_types
1103611047
if t.is_pointer_type(param_type) {
1103711048
mut cur := param_type
1103811049
for cur is types.Alias {
11039-
cur = cur.base_type
11050+
cur = cur.base_type()
1104011051
}
1104111052
if cur is types.Pointer {
11042-
init_typ = cur.base_type
11053+
ptr := cur as types.Pointer
11054+
init_typ = ptr.base_type
1104311055
}
1104411056
}
1104511057
init_pos := t.next_synth_pos()

vlib/v2/types/checker_test.v

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright (c) 2026 Alexander Medvednikov. All rights reserved.
22
// Use of this source code is governed by an MIT license
33
// that can be found in the LICENSE file.
4-
// vtest build: false
54
module types
65

76
import os
@@ -80,7 +79,7 @@ fn test_basic_literal_bool_false() {
8079

8180
fn test_basic_literal_char() {
8281
env := check_code('fn main() { x := `a` }')
83-
assert has_type(env, 'char'), 'char literal should have char type'
82+
assert has_type(env, 'rune'), 'char literal should have rune type'
8483
}
8584

8685
fn test_basic_literal_string() {

vlib/v2/types/types.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ fn FnTypeAttribute.from_ast_attributes(ast_attrs []ast.Attribute) FnTypeAttribut
129129
return attrs
130130
}
131131

132-
struct FnType {
132+
pub struct FnType {
133133
// generic_params []NamedType // T ,Y
134134
generic_params []string // T ,Y
135135
// TODO: save in checker.env? or gere?

0 commit comments

Comments
 (0)