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

checker: fix missing check for taking address of literal value member (#18570)

This commit is contained in:
Felipe Pena 2023-06-27 04:54:03 -03:00 committed by GitHub
parent 3558e05bfb
commit d523bb0306
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 0 deletions

View File

@ -3906,6 +3906,9 @@ fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
c.error('unexpected `&`, expecting expression', node.right.pos)
}
} else if mut node.right is ast.SelectorExpr {
if node.right.expr.is_literal() {
c.error('cannot take the address of a literal value', node.pos.extend(node.right.pos))
}
right_sym := c.table.sym(right_type)
expr_sym := c.table.sym(node.right.expr_type)
if expr_sym.kind == .struct_ && (expr_sym.info as ast.Struct).is_minify

View File

@ -0,0 +1,10 @@
vlib/v/checker/tests/prefix_addr_err.vv:2:2: warning: unused variable: `b`
1 | fn main() {
2 | b := &'foo'.len
| ^
3 | }
vlib/v/checker/tests/prefix_addr_err.vv:2:7: error: cannot take the address of a literal value
1 | fn main() {
2 | b := &'foo'.len
| ~~~~~~~~~~
3 | }

View File

@ -0,0 +1,3 @@
fn main() {
b := &'foo'.len
}