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

parser: perform constant folding before checking size of fixed array (#12126)

This commit is contained in:
ChAoS_UnItY
2021-10-10 06:55:25 +08:00
committed by GitHub
parent 093cab6f56
commit 3647fc6633
3 changed files with 28 additions and 4 deletions

View File

@@ -3,6 +3,7 @@
// that can be found in the LICENSE file.
module parser
import v.transformer
import v.ast
import v.util
import v.token
@@ -26,7 +27,18 @@ pub fn (mut p Parser) parse_array_type() ast.Type {
if const_field.expr is ast.IntegerLiteral {
fixed_size = const_field.expr.val.int()
} else {
show_non_const_error = true
if const_field.expr is ast.InfixExpr {
t := transformer.new_transformer(p.pref)
folded_expr := t.infix_expr(const_field.expr)
if folded_expr is ast.IntegerLiteral {
fixed_size = folded_expr.val.int()
} else {
show_non_const_error = true
}
} else {
show_non_const_error = true
}
}
} else {
if p.pref.is_fmt {