From 53ac6d352f63e932ad2ded4eecdc1fd5758c98c9 Mon Sep 17 00:00:00 2001 From: joe-conigliaro Date: Thu, 18 Jul 2019 18:55:39 +1000 Subject: [PATCH] auto detect u64 const --- compiler/parser.v | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/parser.v b/compiler/parser.v index da46bb564e..fcd2cd40c7 100644 --- a/compiler/parser.v +++ b/compiler/parser.v @@ -2063,10 +2063,15 @@ fn (p mut Parser) factor() string { case .integer: typ = 'int' // Check if float (`1.0`, `1e+3`) but not if is hexa - if (p.lit.contains('.') || p.lit.contains('e')) && - !(p.lit[0] == `0` && p.lit[1] == `x`) { + if (p.lit.contains('.') || (p.lit.contains('e') || p.lit.contains('E'))) && + !(p.lit[0] == `0` && (p.lit[1] == `x` || p.lit[1] == `X`)) { typ = 'f32' // typ = 'f64' // TODO + } else { + v_u64 := p.lit.u64() + if u64(u32(v_u64)) < v_u64 { + typ = 'u64' + } } if p.expected_type != '' && !is_valid_int_const(p.lit, p.expected_type) { p.error('constant `$p.lit` overflows `$p.expected_type`')