ast: check receivers of callexprs too in ast.Table.dependent_names_in_expr (used for finding the constants, that another constant depends on) (#19601)

This commit is contained in:
Delyan Angelov 2023-10-19 17:33:55 +03:00 committed by GitHub
parent 772eb1ed12
commit 79b068bd2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 0 deletions

View File

@ -2342,6 +2342,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string {
names << t.dependent_names_in_expr(expr.init_expr) names << t.dependent_names_in_expr(expr.init_expr)
} }
CallExpr { CallExpr {
if expr.is_method {
names << t.dependent_names_in_expr(expr.left)
}
for arg in expr.args { for arg in expr.args {
names << t.dependent_names_in_expr(arg.expr) names << t.dependent_names_in_expr(arg.expr)
} }

View File

@ -1,3 +1,4 @@
import os
import rand import rand
const ( const (
@ -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}') eprintln('random letter: ${my_random_letter_const.str()} | ASCII code: ${my_random_letter_const}')
assert my_random_letter_const.is_capital() 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 != ''
}