checker: error taking the address of a boolean literal (#7716)
parent
b4f02adc32
commit
13cd7e88ef
|
@ -4367,11 +4367,12 @@ pub fn (mut c Checker) prefix_expr(mut node ast.PrefixExpr) table.Type {
|
||||||
node.right_type = right_type
|
node.right_type = right_type
|
||||||
// TODO: testing ref/deref strategy
|
// TODO: testing ref/deref strategy
|
||||||
if node.op == .amp && !right_type.is_ptr() {
|
if node.op == .amp && !right_type.is_ptr() {
|
||||||
if node.right is ast.IntegerLiteral {
|
match node.right {
|
||||||
c.error('cannot take the address of an int', node.pos)
|
ast.IntegerLiteral { c.error('cannot take the address of an int', node.pos) }
|
||||||
}
|
ast.BoolLiteral { c.error('cannot take the address of a bool', node.pos) }
|
||||||
if node.right is ast.StringLiteral || node.right is ast.StringInterLiteral {
|
ast.StringLiteral, ast.StringInterLiteral { c.error('cannot take the address of a string',
|
||||||
c.error('cannot take the address of a string', node.pos)
|
node.pos) }
|
||||||
|
else {}
|
||||||
}
|
}
|
||||||
if mut node.right is ast.IndexExpr {
|
if mut node.right is ast.IndexExpr {
|
||||||
typ_sym := c.table.get_type_symbol(node.right.left_type)
|
typ_sym := c.table.get_type_symbol(node.right.left_type)
|
||||||
|
|
|
@ -1,24 +1,50 @@
|
||||||
vlib/v/checker/tests/prefix_err.vv:2:5: error: invalid indirect of `int`
|
vlib/v/checker/tests/prefix_err.vv:1:6: error: cannot take the address of a bool
|
||||||
1 | a := 1
|
1 | b := &true
|
||||||
2 | _ = *a
|
|
||||||
| ^
|
| ^
|
||||||
3 | a <- 4
|
2 | _ := &10
|
||||||
4 |
|
3 | _ := &"Hi"
|
||||||
vlib/v/checker/tests/prefix_err.vv:3:1: error: cannot push on non-channel `int`
|
vlib/v/checker/tests/prefix_err.vv:2:6: error: cannot take the address of an int
|
||||||
1 | a := 1
|
1 | b := &true
|
||||||
2 | _ = *a
|
2 | _ := &10
|
||||||
3 | a <- 4
|
|
||||||
| ^
|
| ^
|
||||||
4 |
|
3 | _ := &"Hi"
|
||||||
5 | _ = ~true
|
4 | _ := &"${b}"
|
||||||
vlib/v/checker/tests/prefix_err.vv:5:5: error: operator ~ only defined on int types
|
vlib/v/checker/tests/prefix_err.vv:3:6: error: cannot take the address of a string
|
||||||
3 | a <- 4
|
1 | b := &true
|
||||||
4 |
|
2 | _ := &10
|
||||||
5 | _ = ~true
|
3 | _ := &"Hi"
|
||||||
| ^
|
| ^
|
||||||
6 | _ = !4
|
4 | _ := &"${b}"
|
||||||
vlib/v/checker/tests/prefix_err.vv:6:5: error: ! operator can only be used with bool types
|
5 |
|
||||||
4 |
|
vlib/v/checker/tests/prefix_err.vv:4:6: error: cannot take the address of a string
|
||||||
5 | _ = ~true
|
2 | _ := &10
|
||||||
6 | _ = !4
|
3 | _ := &"Hi"
|
||||||
|
4 | _ := &"${b}"
|
||||||
|
| ^
|
||||||
|
5 |
|
||||||
|
6 | a := 1
|
||||||
|
vlib/v/checker/tests/prefix_err.vv:7:5: error: invalid indirect of `int`
|
||||||
|
5 |
|
||||||
|
6 | a := 1
|
||||||
|
7 | _ = *a
|
||||||
|
| ^
|
||||||
|
8 | a <- 4
|
||||||
|
9 |
|
||||||
|
vlib/v/checker/tests/prefix_err.vv:8:1: error: cannot push on non-channel `int`
|
||||||
|
6 | a := 1
|
||||||
|
7 | _ = *a
|
||||||
|
8 | a <- 4
|
||||||
|
| ^
|
||||||
|
9 |
|
||||||
|
10 | _ = ~true
|
||||||
|
vlib/v/checker/tests/prefix_err.vv:10:5: error: operator ~ only defined on int types
|
||||||
|
8 | a <- 4
|
||||||
|
9 |
|
||||||
|
10 | _ = ~true
|
||||||
|
| ^
|
||||||
|
11 | _ = !4
|
||||||
|
vlib/v/checker/tests/prefix_err.vv:11:5: error: ! operator can only be used with bool types
|
||||||
|
9 |
|
||||||
|
10 | _ = ~true
|
||||||
|
11 | _ = !4
|
||||||
| ^
|
| ^
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
b := &true
|
||||||
|
_ := &10
|
||||||
|
_ := &"Hi"
|
||||||
|
_ := &"${b}"
|
||||||
|
|
||||||
a := 1
|
a := 1
|
||||||
_ = *a
|
_ = *a
|
||||||
a <- 4
|
a <- 4
|
||||||
|
|
Loading…
Reference in New Issue