mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: change [1,2,3]!! to [1,2,3]! (#8101)
This commit is contained in:
@@ -891,7 +891,7 @@ pub:
|
||||
exprs []Expr // `[expr, expr]` or `[expr]Type{}` for fixed array
|
||||
ecmnts [][]Comment // optional iembed comments after each expr
|
||||
is_fixed bool
|
||||
has_val bool // fixed size literal `[expr, expr]!!`
|
||||
has_val bool // fixed size literal `[expr, expr]!`
|
||||
mod string
|
||||
len_expr Expr // len: expr
|
||||
cap_expr Expr // cap: expr
|
||||
|
||||
@@ -111,11 +111,11 @@ println(cc)
|
||||
println(dd)
|
||||
|
||||
// fixed arrays: implemented as normal arrays
|
||||
f1 := [1, 2, 3, 4, 5]!!
|
||||
f1 := [1, 2, 3, 4, 5]!
|
||||
mut f2 := [8]f32
|
||||
f2[0] = f32(1.23)
|
||||
f3 := ['foo', 'bar']!!
|
||||
f4 := [u64(0xffffffffffffffff), 0xdeadface]!!
|
||||
f3 := ['foo', 'bar']!
|
||||
f4 := [u64(0xffffffffffffffff), 0xdeadface]!
|
||||
|
||||
println('
|
||||
$f1
|
||||
|
||||
@@ -88,7 +88,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
||||
}
|
||||
if p.tok.kind == .not && p.tok.line_nr == p.prev_tok.line_nr {
|
||||
last_pos = p.tok.position()
|
||||
p.warn_with_pos('use e.g. `[1, 2, 3]!` instead of `[1, 2, 3]!!`', last_pos)
|
||||
p.error_with_pos('use e.g. `[1, 2, 3]!` instead of `[1, 2, 3]!!`', last_pos)
|
||||
p.next()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ fn test_conv_to_bool() {
|
||||
assert b
|
||||
// check true -> 1
|
||||
assert int(b) == 1
|
||||
|
||||
|
||||
// branchless tests (can be important for manual optimization)
|
||||
arr := [7,8]!!
|
||||
arr := [7,8]!
|
||||
e := arr[int(b)]
|
||||
assert e == 8
|
||||
b = e < 0
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
fn test_fixed_array_lit_init() {
|
||||
a1 := ['1', '2', '3']!!
|
||||
a1 := ['1', '2', '3']!
|
||||
assert typeof(a1).name == '[3]string'
|
||||
assert '$a1' == "['1', '2', '3']"
|
||||
a2 := ['a', 'b']!!
|
||||
a2 := ['a', 'b']!
|
||||
assert typeof(a2).name == '[2]string'
|
||||
assert '$a2' == "['a', 'b']"
|
||||
c1 := [1, 2, 3]!!
|
||||
c1 := [1, 2, 3]!
|
||||
assert typeof(c1).name == '[3]int'
|
||||
assert '$c1' == '[1, 2, 3]'
|
||||
c2 := [i16(1), 2, 3]!!
|
||||
c2 := [i16(1), 2, 3]!
|
||||
assert typeof(c2).name == '[3]i16'
|
||||
assert '$c2' == '[1, 2, 3]'
|
||||
mut c3 := [i64(1), 2, 3]!!
|
||||
mut c3 := [i64(1), 2, 3]!
|
||||
assert typeof(c3).name == '[3]i64'
|
||||
assert '$c3' == '[1, 2, 3]'
|
||||
mut c4 := [u64(1), 2, 3]!!
|
||||
mut c4 := [u64(1), 2, 3]!
|
||||
assert typeof(c4).name == '[3]u64'
|
||||
assert '$c4' == '[1, 2, 3]'
|
||||
mut d1 := [1.1, 2.2, 3.3]!!
|
||||
mut d1 := [1.1, 2.2, 3.3]!
|
||||
assert typeof(d1).name == '[3]f64'
|
||||
assert '$d1' == '[1.1, 2.2, 3.3]'
|
||||
mut d2 := [f32(1.1), 2.2, 3.3]!!
|
||||
mut d2 := [f32(1.1), 2.2, 3.3]!
|
||||
assert typeof(d2).name == '[3]f32'
|
||||
assert '$d2' == '[1.1, 2.2, 3.3]'
|
||||
}
|
||||
@@ -28,21 +28,21 @@ fn test_fixed_array_lit_init() {
|
||||
fn test_fixed_type_init() {
|
||||
a := [2]int{}
|
||||
assert a == [2]int{}
|
||||
assert a == [0, 0]!!
|
||||
assert a == [0, 0]!
|
||||
assert a == a
|
||||
mut c := [3, 3]!!
|
||||
mut c := [3, 3]!
|
||||
assert a != c
|
||||
assert c == [3, 3]!!
|
||||
assert c == [3, 3]!
|
||||
c = [2]int{}
|
||||
assert a == c
|
||||
}
|
||||
|
||||
fn test_fixed_custom_init() {
|
||||
a := [2]byte{init: 7}
|
||||
assert a == [byte(7), 7]!!
|
||||
assert a == [byte(7), 7]!
|
||||
mut b := [3]int{}
|
||||
assert b == [0, 0, 0]!!
|
||||
assert b == [0, 0, 0]!
|
||||
// assign
|
||||
b = [3]int{init: 5}
|
||||
assert b == [5, 5, 5]!!
|
||||
assert b == [5, 5, 5]!
|
||||
}
|
||||
|
||||
@@ -86,56 +86,56 @@ fn test_map_of_bools() {
|
||||
|
||||
fn test_fixed_array_of_floats() {
|
||||
// f64 array
|
||||
aa := [1.2, 3.4, 5.67]!!
|
||||
aa := [1.2, 3.4, 5.67]!
|
||||
assert aa.str() == '[1.2, 3.4, 5.67]'
|
||||
assert '$aa' == '[1.2, 3.4, 5.67]'
|
||||
// f32 array
|
||||
bb := [f32(1.2), 3.4, 5.67]!!
|
||||
bb := [f32(1.2), 3.4, 5.67]!
|
||||
assert bb.str() == '[1.2, 3.4, 5.67]'
|
||||
assert '$bb' == '[1.2, 3.4, 5.67]'
|
||||
}
|
||||
|
||||
fn test_fixed_array_of_bools() {
|
||||
aa := [true, false, true]!!
|
||||
aa := [true, false, true]!
|
||||
assert aa.str() == '[true, false, true]'
|
||||
assert '$aa' == '[true, false, true]'
|
||||
}
|
||||
|
||||
fn test_fixed_array_of_ints() {
|
||||
// int
|
||||
a1 := [11, 22, 33]!!
|
||||
a1 := [11, 22, 33]!
|
||||
assert a1.str() == '[11, 22, 33]'
|
||||
assert '$a1' == '[11, 22, 33]'
|
||||
// u32
|
||||
a2 := [u32(11), 22, 33]!!
|
||||
a2 := [u32(11), 22, 33]!
|
||||
assert a2.str() == '[11, 22, 33]'
|
||||
assert '$a2' == '[11, 22, 33]'
|
||||
// i16
|
||||
b1 := [i16(11), 22, 33]!!
|
||||
b1 := [i16(11), 22, 33]!
|
||||
assert b1.str() == '[11, 22, 33]'
|
||||
assert '$b1' == '[11, 22, 33]'
|
||||
// u16
|
||||
b2 := [u16(11), 22, 33]!!
|
||||
b2 := [u16(11), 22, 33]!
|
||||
assert b2.str() == '[11, 22, 33]'
|
||||
assert '$b2' == '[11, 22, 33]'
|
||||
// i64
|
||||
c1 := [i64(11), 22, 33]!!
|
||||
c1 := [i64(11), 22, 33]!
|
||||
assert c1.str() == '[11, 22, 33]'
|
||||
assert '$c1' == '[11, 22, 33]'
|
||||
// u64
|
||||
c2 := [u64(11), 22, 33]!!
|
||||
c2 := [u64(11), 22, 33]!
|
||||
assert c2.str() == '[11, 22, 33]'
|
||||
assert '$c2' == '[11, 22, 33]'
|
||||
}
|
||||
|
||||
fn test_fixed_array_of_runes() {
|
||||
aa := [`a`, `b`, `c`]!!
|
||||
aa := [`a`, `b`, `c`]!
|
||||
assert aa.str() == '[`a`, `b`, `c`]'
|
||||
assert '$aa' == '[`a`, `b`, `c`]'
|
||||
}
|
||||
|
||||
fn test_fixed_array_of_strings() {
|
||||
aa := ['aa', 'bb', 'cc']!!
|
||||
aa := ['aa', 'bb', 'cc']!
|
||||
assert aa.str() == "['aa', 'bb', 'cc']"
|
||||
assert '$aa' == "['aa', 'bb', 'cc']"
|
||||
}
|
||||
@@ -243,7 +243,7 @@ fn test_alias_in_array() {
|
||||
|
||||
type Alias2 = int
|
||||
fn test_alias_in_fixed_array() {
|
||||
t := [Alias1(1)]!!
|
||||
t := [Alias1(1)]!
|
||||
assert t.str() == '[1]'
|
||||
assert '$t' == '[1]'
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ pub mut:
|
||||
fn test_fixed_array_struct_string_interpolation() {
|
||||
mut ctx := Context{}
|
||||
x := 2.32
|
||||
ctx.vb = [1.1, x, 3.3, 4.4, 5.0, 6.0, 7.0, 8.9]!!
|
||||
ctx.vb = [1.1, x, 3.3, 4.4, 5.0, 6.0, 7.0, 8.9]!
|
||||
s := '$ctx'
|
||||
assert s.starts_with('Context{')
|
||||
assert s.contains('vb: [1.1, 2.32, 3.3, 4.4, 5, 6, 7, 8.9]')
|
||||
|
||||
@@ -14,8 +14,8 @@ fn memcpy(mut dest voidptr, src voidptr, len u32) voidptr {
|
||||
}
|
||||
|
||||
fn test_mut_voidptr_arg() {
|
||||
mut a := [1, 2]!!
|
||||
b := [3, 4]!!
|
||||
mut a := [1, 2]!
|
||||
b := [3, 4]!
|
||||
memcpy(mut a, b, sizeof(int))
|
||||
assert a == [3, 2]!!
|
||||
assert a == [3, 2]!
|
||||
}
|
||||
|
||||
@@ -28,8 +28,8 @@ fn test_type_constructors() {
|
||||
v := `c`
|
||||
assert typeof(&v).name == '&rune'
|
||||
assert typeof(&[v]).name == '&[]rune'
|
||||
assert typeof([v]!!).name == '[1]rune'
|
||||
assert typeof(&[v]!!).name == '&[1]rune'
|
||||
assert typeof([v]!).name == '[1]rune'
|
||||
assert typeof(&[v]!).name == '&[1]rune'
|
||||
assert typeof(&FooBar{}).name == '&FooBar'
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ fn test_typeof_on_sumtypes() {
|
||||
assert typeof(a).name == 'MySumType'
|
||||
assert typeof(b).name == 'MySumType'
|
||||
assert typeof(c).name == 'MySumType'
|
||||
|
||||
|
||||
assert a.str() == '32'
|
||||
assert b.str() == '123.'
|
||||
assert c.str() == 'FooBar'
|
||||
@@ -159,7 +159,7 @@ fn test_generic_type() {
|
||||
v := 5
|
||||
assert type_name(v) == 'int'
|
||||
// assert type_name(&v) == '&int'
|
||||
// assert type_name([v]!!) == '[1]int'
|
||||
// assert type_name([v]!) == '[1]int'
|
||||
assert type_name([v]) == '[]int'
|
||||
assert type_name([[v]]) == '[][]int'
|
||||
assert type_name(FooBar{}) == 'FooBar'
|
||||
|
||||
Reference in New Issue
Block a user