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

expression: set integer literals as int by default

This commit is contained in:
SleepyRoy
2020-03-24 03:05:37 +08:00
committed by GitHub
parent 5c9cbae10d
commit 67ba56c65c
14 changed files with 788 additions and 793 deletions

View File

@ -787,13 +787,7 @@ fn (p mut Parser) factor() string {
}
.number {
// Check if float (`1.0`, `1e+3`) but not if is hexa (e.g. 0xEE contains `E` but is not float)
if (p.lit.contains('.') || p.lit.contains('e') || p.lit.contains('E')) && !(p.lit[..2] in ['0x', '0X']) {
typ = 'f64'
}
else {
v_u64 := p.lit.u64()
typ = if u64(u32(v_u64)) < v_u64 { 'u64' } else { 'int' }
}
typ = if (p.lit.contains('.') || p.lit.contains('e') || p.lit.contains('E')) && !(p.lit[..2] in ['0x', '0X']) { 'f64' } else { 'int' }
if p.expected_type != '' && !is_valid_int_const(p.lit, p.expected_type) {
p.error('constant `$p.lit` overflows `$p.expected_type`')
}