auto detect u64 const

pull/1226/head
joe-conigliaro 2019-07-18 18:55:39 +10:00 committed by Alexander Medvednikov
parent 43070412f7
commit 53ac6d352f
1 changed files with 7 additions and 2 deletions

View File

@ -2063,10 +2063,15 @@ fn (p mut Parser) factor() string {
case .integer: case .integer:
typ = 'int' typ = 'int'
// Check if float (`1.0`, `1e+3`) but not if is hexa // Check if float (`1.0`, `1e+3`) but not if is hexa
if (p.lit.contains('.') || p.lit.contains('e')) && if (p.lit.contains('.') || (p.lit.contains('e') || p.lit.contains('E'))) &&
!(p.lit[0] == `0` && p.lit[1] == `x`) { !(p.lit[0] == `0` && (p.lit[1] == `x` || p.lit[1] == `X`)) {
typ = 'f32' typ = 'f32'
// typ = 'f64' // TODO // 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) { if p.expected_type != '' && !is_valid_int_const(p.lit, p.expected_type) {
p.error('constant `$p.lit` overflows `$p.expected_type`') p.error('constant `$p.lit` overflows `$p.expected_type`')