mirror of
https://github.com/vlang/v.git
synced 2025-09-12 00:46:55 -04:00
This commit is contained in:
parent
c77292ac2c
commit
66ac23fc57
@ -1051,6 +1051,7 @@ An array can be of these types:
|
|||||||
| Thread | `[]thread int` |
|
| Thread | `[]thread int` |
|
||||||
| Reference | `[]&f64` |
|
| Reference | `[]&f64` |
|
||||||
| Shared | `[]shared MyStructType` |
|
| Shared | `[]shared MyStructType` |
|
||||||
|
| Option | `[]?f64` |
|
||||||
|
|
||||||
**Example Code:**
|
**Example Code:**
|
||||||
|
|
||||||
|
@ -29,13 +29,17 @@ fn (mut p Parser) array_init(is_option bool, alias_array_type ast.Type) ast.Arra
|
|||||||
line_nr := p.tok.line_nr
|
line_nr := p.tok.line_nr
|
||||||
p.next()
|
p.next()
|
||||||
// []string
|
// []string
|
||||||
if p.tok.kind in [.name, .amp, .lsbr, .question, .key_shared]
|
if p.tok.kind in [.name, .amp, .lsbr, .question, .key_shared, .not]
|
||||||
&& p.tok.line_nr == line_nr {
|
&& p.tok.line_nr == line_nr {
|
||||||
elem_type_pos = p.tok.pos()
|
elem_type_pos = p.tok.pos()
|
||||||
elem_type = p.parse_type()
|
elem_type = p.parse_type()
|
||||||
// this is set here because it's a known type, others could be the
|
// this is set here because it's a known type, others could be the
|
||||||
// result of expr so we do those in checker
|
// result of expr so we do those in checker
|
||||||
if elem_type != 0 {
|
if elem_type != 0 {
|
||||||
|
if elem_type.has_flag(.result) {
|
||||||
|
p.error_with_pos('arrays do not support storing Result values',
|
||||||
|
elem_type_pos)
|
||||||
|
}
|
||||||
idx := p.table.find_or_register_array(elem_type)
|
idx := p.table.find_or_register_array(elem_type)
|
||||||
if elem_type.has_flag(.generic) {
|
if elem_type.has_flag(.generic) {
|
||||||
array_type = ast.new_type(idx).set_flag(.generic)
|
array_type = ast.new_type(idx).set_flag(.generic)
|
||||||
|
@ -3,10 +3,17 @@ vlib/v/parser/tests/array_init.vv:2:7: warning: use `x := []Type{}` instead of `
|
|||||||
2 | _ := []int
|
2 | _ := []int
|
||||||
| ~~~~~
|
| ~~~~~
|
||||||
3 | _ := [1]int
|
3 | _ := [1]int
|
||||||
4 | }
|
4 | _ := []!int{}
|
||||||
vlib/v/parser/tests/array_init.vv:3:7: warning: use e.g. `x := [1]Type{}` instead of `x := [1]Type`
|
vlib/v/parser/tests/array_init.vv:3:7: warning: use e.g. `x := [1]Type{}` instead of `x := [1]Type`
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | _ := []int
|
2 | _ := []int
|
||||||
3 | _ := [1]int
|
3 | _ := [1]int
|
||||||
| ~~~~~~
|
| ~~~~~~
|
||||||
4 | }
|
4 | _ := []!int{}
|
||||||
|
5 | }
|
||||||
|
vlib/v/parser/tests/array_init.vv:4:9: error: arrays do not support storing Result values
|
||||||
|
2 | _ := []int
|
||||||
|
3 | _ := [1]int
|
||||||
|
4 | _ := []!int{}
|
||||||
|
| ^
|
||||||
|
5 | }
|
@ -1,4 +1,5 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
_ := []int
|
_ := []int
|
||||||
_ := [1]int
|
_ := [1]int
|
||||||
|
_ := []!int{}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user