1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

table: i8 -128 was being cast to int closes #4164

This commit is contained in:
joe-conigliaro 2020-03-31 16:07:30 +11:00
parent 3b621c0ce6
commit f58875a202
No known key found for this signature in database
GPG Key ID: C12F7136C08206F1

View File

@ -903,22 +903,26 @@ fn (table &Table) cgen_name_type_pair(name, typ string) string {
} }
fn is_valid_int_const(val, typ string) bool { fn is_valid_int_const(val, typ string) bool {
x := val.int() // x := val.int()
return match typ { match typ {
'char'{ 'char'{
0 <= x && x <= 255 x := val.int()
return 0 <= x && x <= 255
} }
'byte'{ 'byte'{
0 <= x && x <= 255 x := val.int()
return 0 <= x && x <= 255
} }
'u16'{ 'u16'{
0 <= x && x <= 65535 x := val.u16()
return 0 <= x && x <= 65535
} }
// case 'u32': return 0 <= x && x <= math.MaxU32 // case 'u32': return 0 <= x && x <= math.MaxU32
// case 'u64': return 0 <= x && x <= math.MaxU64 // case 'u64': return 0 <= x && x <= math.MaxU64
// //////////// // ////////////
'i8'{ 'i8'{
-128 <= x && x <= 127 x := val.i8()
return -128 <= x && x <= 127
} }
/* /*
case 'i16': return math.min_i16 <= x && x <= math.max_i16 case 'i16': return math.min_i16 <= x && x <= math.max_i16
@ -929,7 +933,7 @@ fn is_valid_int_const(val, typ string) bool {
// x64 := val.i64() // x64 := val.i64()
// return i64(-(1<<63)) <= x64 && x64 <= i64((1<<63)-1) // return i64(-(1<<63)) <= x64 && x64 <= i64((1<<63)-1)
else { else {
true}} return true}}
} }
fn (p mut Parser) typ_to_fmt(typ string, level int) string { fn (p mut Parser) typ_to_fmt(typ string, level int) string {