Skip to content

Commit

Permalink
ast: check receivers of callexprs too in ast.Table.dependent_names_in…
Browse files Browse the repository at this point in the history
…_expr (used for finding the constants, that another constant depends on) (#19601)
  • Loading branch information
spytheman authored Oct 19, 2023
1 parent 772eb1e commit 79b068b
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -2342,6 +2342,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string {
names << t.dependent_names_in_expr(expr.init_expr)
}
CallExpr {
if expr.is_method {
names << t.dependent_names_in_expr(expr.left)
}
for arg in expr.args {
names << t.dependent_names_in_expr(arg.expr)
}
Expand Down
16 changes: 16 additions & 0 deletions vlib/v/tests/const_init_order_test.v
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
import rand

const (
Expand All @@ -8,3 +9,18 @@ fn test_rand_is_initialized_before_main() {
eprintln('random letter: ${my_random_letter_const.str()} | ASCII code: ${my_random_letter_const}')
assert my_random_letter_const.is_capital()
}

//

const (
last_constant = fn_that_calls_a_method_on_a_constant()
a_constant = os.join_path(@VROOT, 'a')
)

fn fn_that_calls_a_method_on_a_constant() string {
return a_constant.replace('\\', '/')
}

fn test_consts_initialised_with_a_function_that_uses_other_consts_as_receivers_are_properly_ordered() {
assert last_constant != ''
}

0 comments on commit 79b068b

Please sign in to comment.