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:
parent
3558e05bfb
commit
d523bb0306
@ -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
|
||||
|
10
vlib/v/checker/tests/prefix_addr_err.out
Normal file
10
vlib/v/checker/tests/prefix_addr_err.out
Normal 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 | }
|
3
vlib/v/checker/tests/prefix_addr_err.vv
Normal file
3
vlib/v/checker/tests/prefix_addr_err.vv
Normal file
@ -0,0 +1,3 @@
|
||||
fn main() {
|
||||
b := &'foo'.len
|
||||
}
|
Loading…
Reference in New Issue
Block a user