From f58875a202e91ca6e558848d97088255a8a12859 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Tue, 31 Mar 2020 16:07:30 +1100 Subject: [PATCH] table: i8 -128 was being cast to int closes #4164 --- vlib/compiler/table.v | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vlib/compiler/table.v b/vlib/compiler/table.v index 2c411b299e..0baba45b30 100644 --- a/vlib/compiler/table.v +++ b/vlib/compiler/table.v @@ -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 {