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

auto detect u64 const

This commit is contained in:
joe-conigliaro 2019-07-18 18:55:39 +10:00 committed by Alexander Medvednikov
parent 43070412f7
commit 53ac6d352f

View File

@ -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`')