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

pull/4161/head
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
1 changed files with 11 additions and 7 deletions

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 {
x := val.int()
return match typ {
// x := val.int()
match typ {
'char'{
0 <= x && x <= 255
x := val.int()
return 0 <= x && x <= 255
}
'byte'{
0 <= x && x <= 255
x := val.int()
return 0 <= x && x <= 255
}
'u16'{
0 <= x && x <= 65535
x := val.u16()
return 0 <= x && x <= 65535
}
// case 'u32': return 0 <= x && x <= math.MaxU32
// case 'u64': return 0 <= x && x <= math.MaxU64
// ////////////
'i8'{
-128 <= x && x <= 127
x := val.i8()
return -128 <= x && x <= 127
}
/*
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()
// return i64(-(1<<63)) <= x64 && x64 <= i64((1<<63)-1)
else {
true}}
return true}}
}
fn (p mut Parser) typ_to_fmt(typ string, level int) string {