vlib: fix missing `else{}` in match statements

pull/3006/head
Alexander Medvednikov 2019-12-07 17:13:25 +03:00
parent 2fb7fba856
commit ad6adf327e
15 changed files with 88 additions and 85 deletions

View File

@ -402,6 +402,7 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
game.state = .running game.state = .running
} }
} }
else {}
} }
if game.state != .running { if game.state != .running {
@ -434,5 +435,6 @@ fn key_down(wnd voidptr, key, code, action, mods int) {
glfw.KeyDown { glfw.KeyDown {
game.move_tetro() // drop faster when the player presses <down> game.move_tetro() // drop faster when the player presses <down>
} }
else { }
} }
} }

View File

@ -117,6 +117,9 @@ fn test_hamming() {
input1.setbit(i) input1.setbit(i)
input2.setbit(i) input2.setbit(i)
} }
else {
}
} }
} }
assert count == bitfield.hamming(input1, input2) assert count == bitfield.hamming(input1, input2)

View File

@ -120,7 +120,7 @@ pub fn string_from_wide(_wstr &u16) string {
pub fn string_from_wide2(_wstr &u16, len int) string { pub fn string_from_wide2(_wstr &u16, len int) string {
$if windows { $if windows {
num_chars := C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, 0, 0, 0, 0)) num_chars := C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, 0, 0, 0, 0)
mut str_to := malloc(num_chars + 1) mut str_to := malloc(num_chars + 1)
if !isnil(str_to) { if !isnil(str_to) {
C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, str_to, num_chars, 0, 0) C.WideCharToMultiByte(CP_UTF8, 0, _wstr, len, str_to, num_chars, 0, 0)

View File

@ -203,14 +203,8 @@ fn (p mut Parser) match_statement(is_expr bool) string {
i++ i++
p.fgen_nl() p.fgen_nl()
} }
p.error('match expression requires `else`')
//if is_expr { //p.returns = false // only get here when no default, so return is not guaranteed
// we get here if no else found, ternary requires "else" branch
p.warn('match expression requires `else`')
//}
p.returns = false // only get here when no default, so return is not guaranteed
return '' return ''
} }

View File

@ -51,6 +51,7 @@ fn test_match_integers() {
a = a + 2 a = a + 2
a = a + 2 a = a + 2
} }
else {}
} }
assert a == 6 assert a == 6

View File

@ -5,7 +5,7 @@
module base64 module base64
const ( const (
Index = [int(0), 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Index = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0, 62, 63, 62, 62, 63, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 0, 0, 0,
0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,

View File

@ -58,6 +58,7 @@ pub fn (w mut Writer) write(record []string) ?bool {
`\r`, `\n` { `\r`, `\n` {
w.sb.write(le) w.sb.write(le)
} }
else {}
} }
field = field[1..] field = field[1..]
} }

View File

@ -90,7 +90,7 @@ fn up_low(s string, upper_flag bool) string {
} }
} }
else if ch_len > 1 && ch_len < 5{ else if ch_len > 1 && ch_len < 5{
mut lword := int(0) mut lword := 0
for i:=0; i < ch_len ; i++ { for i:=0; i < ch_len ; i++ {
lword = (lword << 8 ) | int( s.str[_index + i] ) lword = (lword << 8 ) | int( s.str[_index + i] )

View File

@ -382,7 +382,7 @@ pub fn (ctx &GG) draw_line_c(x, y, x2, y2 f32, color gx.Color) {
C.glDeleteBuffers(1, &ctx.vbo) C.glDeleteBuffers(1, &ctx.vbo)
ctx.shader.use() ctx.shader.use()
ctx.shader.set_color('color', color) ctx.shader.set_color('color', color)
vertices := [f32(x), f32(y), f32(x2), f32(y2)] ! vertices := [x, y, x2, y2] !
gl.bind_vao(ctx.vao) gl.bind_vao(ctx.vao)
gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW) gl.set_vbo(ctx.vbo, vertices, C.GL_STATIC_DRAW)
gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0) gl.vertex_attrib_pointer(0, 2, C.GL_FLOAT, false, 2, 0)
@ -433,7 +433,7 @@ pub fn (ctx &GG) draw_image(x, y, w, h f32, tex_id u32) {
gl.enable_vertex_attrib_array(1) gl.enable_vertex_attrib_array(1)
gl.vertex_attrib_pointer(2, 2, C.GL_FLOAT, false, 8, 6) gl.vertex_attrib_pointer(2, 2, C.GL_FLOAT, false, 8, 6)
gl.enable_vertex_attrib_array(2) gl.enable_vertex_attrib_array(2)
gl.bind_2d_texture(u32(tex_id)) gl.bind_2d_texture(tex_id)
gl.bind_vao(ctx.vao) gl.bind_vao(ctx.vao)
gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0) gl.draw_elements(C.GL_TRIANGLES, 6, C.GL_UNSIGNED_INT, 0)
} }

View File

@ -166,8 +166,8 @@ pub fn ortho(left, right, bottom, top f32) Mat4 {
// mat<4, 4, T, defaultp> Result(static_cast<T>(1)); // mat<4, 4, T, defaultp> Result(static_cast<T>(1));
n := 16 n := 16
mut res := f32_calloc(n) mut res := f32_calloc(n)
res[0] = 2.0 / f32(right - left) res[0] = 2.0 / (right - left)
res[5] = 2.0 / f32(top - bottom) res[5] = 2.0 / (top - bottom)
res[10] = 1.0 res[10] = 1.0
res[12] = - (right + left) / (right - left) res[12] = - (right + left) / (right - left)
res[13] = - (top + bottom) / (top - bottom) res[13] = - (top + bottom) / (top - bottom)

View File

@ -74,7 +74,7 @@ fn jsdecode_f32(root &C.cJSON) f32 {
if isnil(root) { if isnil(root) {
return f32(0) return f32(0)
} }
return f32(root.valuedouble) return root.valuedouble
} }
fn jsdecode_f64(root &C.cJSON) f64 { fn jsdecode_f64(root &C.cJSON) f64 {

View File

@ -12,8 +12,8 @@ const (
mask = 0x7FF mask = 0x7FF
shift = 64 - 11 - 1 shift = 64 - 11 - 1
bias = 1023 bias = 1023
sign_mask = u64(u64(1) << 63) sign_mask = (u64(1) << 63)
frac_mask = u64(u64(u64(1)<<u64(shift)) - u64(1)) frac_mask = ((u64(1)<<u64(shift)) - u64(1))
) )
// inf returns positive infinity if sign >= 0, negative infinity if sign < 0. // inf returns positive infinity if sign >= 0, negative infinity if sign < 0.

View File

@ -140,9 +140,9 @@ pub fn factorial(n f64) f64 {
return max_f64 return max_f64
} }
/* Otherwise return n!. */ // Otherwise return n!.
if n == f64(i64(n)) && n >= 0.0 { if n == f64(i64(n)) && n >= 0.0 {
return f64(factorials[i64(n)]) return factorials[i64(n)]
} }
return gamma(n + 1.0) return gamma(n + 1.0)

View File

@ -277,7 +277,7 @@ pub fn (s Socket) read_line() string {
mut res := '' // The final result, including the ending \n. mut res := '' // The final result, including the ending \n.
for { for {
mut line := '' // The current line. Can be a partial without \n in it. mut line := '' // The current line. Can be a partial without \n in it.
n := int(C.recv(s.sockfd, buf, MAX_READ-1, MSG_PEEK)) n := C.recv(s.sockfd, buf, MAX_READ-1, MSG_PEEK)
if n == -1 { return res } if n == -1 { return res }
if n == 0 { return res } if n == 0 { return res }
buf[n] = `\0` buf[n] = `\0`

View File

@ -103,8 +103,9 @@ fn should_escape(c byte, mode EncodingMode) bool {
// everything, so escape nothing. // everything, so escape nothing.
return false return false
} }
else {}
} }
} } else {}
} }
if mode == .encode_fragment { if mode == .encode_fragment {
@ -118,6 +119,7 @@ fn should_escape(c byte, mode EncodingMode) bool {
`!`, `(`, `)`, `*`{ `!`, `(`, `)`, `*`{
return false return false
} }
else {}
} }
} }
@ -184,7 +186,7 @@ fn unescape(s_ string, mode EncodingMode) ?string {
// That is, you can use escaping in the zone identifier but not // That is, you can use escaping in the zone identifier but not
// to introduce bytes you couldn't just write directly. // to introduce bytes you couldn't just write directly.
// But Windows puts spaces here! Yay. // But Windows puts spaces here! Yay.
v := byte(unhex(s[i+1])<<byte(4) | unhex(s[i+2])) v := (unhex(s[i+1])<<byte(4) | unhex(s[i+2]))
if s[i..i+3] != '%25' && v != ` ` && should_escape(v, .encode_host) { if s[i..i+3] != '%25' && v != ` ` && should_escape(v, .encode_host) {
error(error_msg(err_msg_escape, s[i..i+3])) error(error_msg(err_msg_escape, s[i..i+3]))
} }
@ -212,7 +214,7 @@ fn unescape(s_ string, mode EncodingMode) ?string {
x := s[i] x := s[i]
match x { match x {
`%` { `%` {
t.write( byte(unhex(s[i+1])<<byte(4) | unhex(s[i+2])).str() ) t.write((unhex(s[i+1])<<byte(4) | unhex(s[i+2])).str() )
i += 2 i += 2
} }
`+` { `+` {