1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

ast: fix const dependency order for consts initialised with ast.SelectorExpr (fix #15049) (#17064)

This commit is contained in:
Delyan Angelov 2023-01-22 09:34:46 +02:00 committed by GitHub
parent 0ac6ba9354
commit 0bafd237ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 32 additions and 1 deletions

View File

@ -2339,6 +2339,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string {
PrefixExpr {
names << t.dependent_names_in_expr(expr.right)
}
SelectorExpr {
names << t.dependent_names_in_expr(expr.expr)
}
StructInit {
for field in expr.fields {
names << t.dependent_names_in_expr(field.expr)

View File

@ -10,7 +10,9 @@ const (
fn test_const_call_expr_order() {
dump(cache_dir)
dump(shdc)
assert true
assert shdc.contains(cache_dir)
assert shdc.contains(tool_name)
assert shdc.ends_with(shdc_exe_name)
}
fn shdc_exe() string {

View File

@ -0,0 +1,26 @@
struct Abc {
version string
name string
}
fn abc() !Abc {
return Abc{
version: 'abc'
name: 'xyz'
}
}
// Note: version depends on a field in manifest, even though it is declared before it
pub const version = manifest.version
pub const manifest = abc() or { panic(err) }
// Note: name depends on a field in manifest too, but it is declared after it
pub const name = manifest.name
fn test_order_of_const_initialisation_should_take_into_account_selector_expressions() {
println(version)
println(name)
assert version == 'abc'
assert name == 'xyz'
}