checker: forbid multiple pointer yields (#11105)

pull/11112/head
Daniel Däschle 2021-08-09 01:11:53 +02:00 committed by GitHub
parent eed8c4671f
commit a64b191ce5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 0 deletions

View File

@ -7117,6 +7117,13 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) ast.Type {
right_type := c.expr(node.right)
c.inside_ref_lit = old_inside_ref_lit
node.right_type = right_type
if node.op == .amp {
if mut node.right is ast.PrefixExpr {
if node.right.op == .amp {
c.error('unexpected `&`, expecting expression', node.right.pos)
}
}
}
// TODO: testing ref/deref strategy
if node.op == .amp && !right_type.is_ptr() {
mut expr := node.right

View File

@ -0,0 +1,6 @@
vlib/v/checker/tests/multiple_pointer_yield_err.vv:9:8: error: unexpected `&`, expecting expression
7 | fn main() {
8 | f := Fail{}
9 | foo(&&&f)
| ^
10 | }

View File

@ -0,0 +1,10 @@
struct Fail {
name string
}
fn foo(bar &&&Fail) {}
fn main() {
f := Fail{}
foo(&&&f)
}