Skip to content

Commit 4d0cba5

Browse files
committed
Relax new overflow error as warning
1 parent f7cca9a commit 4d0cba5

File tree

2 files changed

+36
-23
lines changed

2 files changed

+36
-23
lines changed

vlib/v/checker/checker.v

+11-3
Original file line numberDiff line numberDiff line change
@@ -3665,6 +3665,8 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
36653665
match e {
36663666
0 {}
36673667
-3 {
3668+
// FIXME: Once integer literal is considered as hard error, remove this warn and migrate to later error
3669+
c.error('value `${node.expr.val}` overflows `${tt}`', node.pos)
36683670
is_overflowed = true
36693671
}
36703672
else {
@@ -3704,11 +3706,17 @@ fn (mut c Checker) cast_expr(mut node ast.CastExpr) ast.Type {
37043706

37053707
is_overflowed = v == signed_one || (signed && v - 2 == max_signed)
37063708
|| (!signed && v - 1 == max_signed)
3709+
// FIXME: Once integer literal is considered as hard error, remove this warn and migrate to later error
3710+
if is_overflowed {
3711+
c.warn('value `${node.expr.val}` overflows `${tt}`, this will be considered hard error soon',
3712+
node.pos)
3713+
}
37073714
}
37083715

3709-
if is_overflowed {
3710-
c.error('value `${node.expr.val}` overflows `${tt}`', node.pos)
3711-
}
3716+
// FIXME: Once integer literal is considered as hard error, uncomment this
3717+
// if is_overflowed {
3718+
// c.error('value `${node.expr.val}` overflows `${tt}`', node.pos)
3719+
// }
37123720
} else if to_type.is_float() && mut node.expr is ast.FloatLiteral {
37133721
tt := c.table.type_to_str(to_type)
37143722
strconv.atof64(node.expr.val) or {
Original file line numberDiff line numberDiff line change
@@ -1,139 +1,144 @@
1-
vlib/v/checker/tests/overflow_int_signed_err.vv:2:2: error: value `0xff` overflows `i8`
1+
vlib/v/checker/tests/overflow_int_signed_err.vv:2:2: warning: value `0xff` overflows `i8`, this will be considered hard error soon
22
1 | i8s := [
33
2 | i8(0xff), // converted to -1
44
| ~~~~~~~~
55
3 | i8(128), // converted to -128
66
4 | i8(-129), // converted to +127
7-
vlib/v/checker/tests/overflow_int_signed_err.vv:3:2: error: value `128` overflows `i8`
7+
vlib/v/checker/tests/overflow_int_signed_err.vv:3:2: warning: value `128` overflows `i8`, this will be considered hard error soon
88
1 | i8s := [
99
2 | i8(0xff), // converted to -1
1010
3 | i8(128), // converted to -128
1111
| ~~~~~~~
1212
4 | i8(-129), // converted to +127
1313
5 | i8(-0xff), // converted to +1
14-
vlib/v/checker/tests/overflow_int_signed_err.vv:4:2: error: value `-129` overflows `i8`
14+
vlib/v/checker/tests/overflow_int_signed_err.vv:4:2: warning: value `-129` overflows `i8`, this will be considered hard error soon
1515
2 | i8(0xff), // converted to -1
1616
3 | i8(128), // converted to -128
1717
4 | i8(-129), // converted to +127
1818
| ~~~~~~~~
1919
5 | i8(-0xff), // converted to +1
2020
6 | ]
21-
vlib/v/checker/tests/overflow_int_signed_err.vv:5:2: error: value `-0xff` overflows `i8`
21+
vlib/v/checker/tests/overflow_int_signed_err.vv:5:2: warning: value `-0xff` overflows `i8`, this will be considered hard error soon
2222
3 | i8(128), // converted to -128
2323
4 | i8(-129), // converted to +127
2424
5 | i8(-0xff), // converted to +1
2525
| ~~~~~~~~~
2626
6 | ]
2727
7 |
28-
vlib/v/checker/tests/overflow_int_signed_err.vv:9:2: error: value `0xffff` overflows `i16`
28+
vlib/v/checker/tests/overflow_int_signed_err.vv:9:2: warning: value `0xffff` overflows `i16`, this will be considered hard error soon
2929
7 |
3030
8 | i16s := [
3131
9 | i16(0xffff), // converted to -1
3232
| ~~~~~~~~~~~
3333
10 | i16(32768), // converted to -32768
3434
11 | i16(-32769), // converted to +32767
35-
vlib/v/checker/tests/overflow_int_signed_err.vv:10:2: error: value `32768` overflows `i16`
35+
vlib/v/checker/tests/overflow_int_signed_err.vv:10:2: warning: value `32768` overflows `i16`, this will be considered hard error soon
3636
8 | i16s := [
3737
9 | i16(0xffff), // converted to -1
3838
10 | i16(32768), // converted to -32768
3939
| ~~~~~~~~~~
4040
11 | i16(-32769), // converted to +32767
4141
12 | i16(-0xffff), // converted to +1
42-
vlib/v/checker/tests/overflow_int_signed_err.vv:11:2: error: value `-32769` overflows `i16`
42+
vlib/v/checker/tests/overflow_int_signed_err.vv:11:2: warning: value `-32769` overflows `i16`, this will be considered hard error soon
4343
9 | i16(0xffff), // converted to -1
4444
10 | i16(32768), // converted to -32768
4545
11 | i16(-32769), // converted to +32767
4646
| ~~~~~~~~~~~
4747
12 | i16(-0xffff), // converted to +1
4848
13 | ]
49-
vlib/v/checker/tests/overflow_int_signed_err.vv:12:2: error: value `-0xffff` overflows `i16`
49+
vlib/v/checker/tests/overflow_int_signed_err.vv:12:2: warning: value `-0xffff` overflows `i16`, this will be considered hard error soon
5050
10 | i16(32768), // converted to -32768
5151
11 | i16(-32769), // converted to +32767
5252
12 | i16(-0xffff), // converted to +1
5353
| ~~~~~~~~~~~~
5454
13 | ]
5555
14 |
56-
vlib/v/checker/tests/overflow_int_signed_err.vv:16:2: error: value `0xffffffff` overflows `int`
56+
vlib/v/checker/tests/overflow_int_signed_err.vv:16:2: warning: value `0xffffffff` overflows `int`, this will be considered hard error soon
5757
14 |
5858
15 | ints := [
5959
16 | int(0xffffffff), // converted to -1
6060
| ~~~~~~~~~~~~~~~
6161
17 | int(2147483648), // converted to -2147483648 (overflow in 32-bit int)
6262
18 | int(-2147483649), // converted to +2147483647 (overflow)
63-
vlib/v/checker/tests/overflow_int_signed_err.vv:17:2: error: value `2147483648` overflows `int`
63+
vlib/v/checker/tests/overflow_int_signed_err.vv:17:2: warning: value `2147483648` overflows `int`, this will be considered hard error soon
6464
15 | ints := [
6565
16 | int(0xffffffff), // converted to -1
6666
17 | int(2147483648), // converted to -2147483648 (overflow in 32-bit int)
6767
| ~~~~~~~~~~~~~~~
6868
18 | int(-2147483649), // converted to +2147483647 (overflow)
6969
19 | int(-0xffffffff), // converted to +1
70-
vlib/v/checker/tests/overflow_int_signed_err.vv:18:2: error: value `-2147483649` overflows `int`
70+
vlib/v/checker/tests/overflow_int_signed_err.vv:18:2: warning: value `-2147483649` overflows `int`, this will be considered hard error soon
7171
16 | int(0xffffffff), // converted to -1
7272
17 | int(2147483648), // converted to -2147483648 (overflow in 32-bit int)
7373
18 | int(-2147483649), // converted to +2147483647 (overflow)
7474
| ~~~~~~~~~~~~~~~~
7575
19 | int(-0xffffffff), // converted to +1
7676
20 | ]
77-
vlib/v/checker/tests/overflow_int_signed_err.vv:19:2: error: value `-0xffffffff` overflows `int`
77+
vlib/v/checker/tests/overflow_int_signed_err.vv:19:2: warning: value `-0xffffffff` overflows `int`, this will be considered hard error soon
7878
17 | int(2147483648), // converted to -2147483648 (overflow in 32-bit int)
7979
18 | int(-2147483649), // converted to +2147483647 (overflow)
8080
19 | int(-0xffffffff), // converted to +1
8181
| ~~~~~~~~~~~~~~~~
8282
20 | ]
8383
21 |
84-
vlib/v/checker/tests/overflow_int_signed_err.vv:23:2: error: value `0xffffffff` overflows `i32`
84+
vlib/v/checker/tests/overflow_int_signed_err.vv:23:2: warning: value `0xffffffff` overflows `i32`, this will be considered hard error soon
8585
21 |
8686
22 | i32s := [
8787
23 | i32(0xffffffff), // converted to -1
8888
| ~~~~~~~~~~~~~~~
8989
24 | i32(2147483648), // converted to -2147483648
9090
25 | i32(-2147483649), // converted to +2147483647
91-
vlib/v/checker/tests/overflow_int_signed_err.vv:24:2: error: value `2147483648` overflows `i32`
91+
vlib/v/checker/tests/overflow_int_signed_err.vv:24:2: warning: value `2147483648` overflows `i32`, this will be considered hard error soon
9292
22 | i32s := [
9393
23 | i32(0xffffffff), // converted to -1
9494
24 | i32(2147483648), // converted to -2147483648
9595
| ~~~~~~~~~~~~~~~
9696
25 | i32(-2147483649), // converted to +2147483647
9797
26 | i32(-0xffffffff), // converted to +1
98-
vlib/v/checker/tests/overflow_int_signed_err.vv:25:2: error: value `-2147483649` overflows `i32`
98+
vlib/v/checker/tests/overflow_int_signed_err.vv:25:2: warning: value `-2147483649` overflows `i32`, this will be considered hard error soon
9999
23 | i32(0xffffffff), // converted to -1
100100
24 | i32(2147483648), // converted to -2147483648
101101
25 | i32(-2147483649), // converted to +2147483647
102102
| ~~~~~~~~~~~~~~~~
103103
26 | i32(-0xffffffff), // converted to +1
104104
27 | ]
105-
vlib/v/checker/tests/overflow_int_signed_err.vv:26:2: error: value `-0xffffffff` overflows `i32`
105+
vlib/v/checker/tests/overflow_int_signed_err.vv:26:2: warning: value `-0xffffffff` overflows `i32`, this will be considered hard error soon
106106
24 | i32(2147483648), // converted to -2147483648
107107
25 | i32(-2147483649), // converted to +2147483647
108108
26 | i32(-0xffffffff), // converted to +1
109109
| ~~~~~~~~~~~~~~~~
110110
27 | ]
111111
28 |
112-
vlib/v/checker/tests/overflow_int_signed_err.vv:30:2: error: value `0xffffffffffffffff` overflows `i64`
112+
vlib/v/checker/tests/overflow_int_signed_err.vv:30:2: warning: value `0xffffffffffffffff` overflows `i64`, this will be considered hard error soon
113113
28 |
114114
29 | i64s := [
115115
30 | i64(0xffffffffffffffff), // converted to -1
116116
| ~~~~~~~~~~~~~~~~~~~~~~~
117117
31 | i64(9223372036854775808), // converted to -9223372036854775808
118118
32 | i64(-9223372036854775809), // converted to +9223372036854775807
119-
vlib/v/checker/tests/overflow_int_signed_err.vv:31:2: error: value `9223372036854775808` overflows `i64`
119+
vlib/v/checker/tests/overflow_int_signed_err.vv:31:2: warning: value `9223372036854775808` overflows `i64`, this will be considered hard error soon
120120
29 | i64s := [
121121
30 | i64(0xffffffffffffffff), // converted to -1
122122
31 | i64(9223372036854775808), // converted to -9223372036854775808
123123
| ~~~~~~~~~~~~~~~~~~~~~~~~
124124
32 | i64(-9223372036854775809), // converted to +9223372036854775807
125125
33 | i64(-0xffffffffffffffff), // converted to +1
126-
vlib/v/checker/tests/overflow_int_signed_err.vv:32:2: error: value `-9223372036854775809` overflows `i64`
126+
vlib/v/checker/tests/overflow_int_signed_err.vv:32:2: warning: value `-9223372036854775809` overflows `i64`, this will be considered hard error soon
127127
30 | i64(0xffffffffffffffff), // converted to -1
128128
31 | i64(9223372036854775808), // converted to -9223372036854775808
129129
32 | i64(-9223372036854775809), // converted to +9223372036854775807
130130
| ~~~~~~~~~~~~~~~~~~~~~~~~~
131131
33 | i64(-0xffffffffffffffff), // converted to +1
132132
34 | ]
133-
vlib/v/checker/tests/overflow_int_signed_err.vv:33:2: error: value `-0xffffffffffffffff` overflows `i64`
133+
vlib/v/checker/tests/overflow_int_signed_err.vv:33:2: warning: value `-0xffffffffffffffff` overflows `i64`, this will be considered hard error soon
134134
31 | i64(9223372036854775808), // converted to -9223372036854775808
135135
32 | i64(-9223372036854775809), // converted to +9223372036854775807
136136
33 | i64(-0xffffffffffffffff), // converted to +1
137137
| ~~~~~~~~~~~~~~~~~~~~~~~~
138138
34 | ]
139139
35 |
140+
i8s: [-1, -128, 127, 1]
141+
i16s: [-1, -32768, 32767, 1]
142+
ints: [-1, -2147483648, 2147483647, 1]
143+
i32s: [-1, -2147483648, 2147483647, 1]
144+
i64s: [-1, -9223372036854775808, 9223372036854775807, 1]

0 commit comments

Comments
 (0)