scanner: clarify the float literal warning (#11313)

pull/11324/head
William Gooch 2021-08-27 09:49:29 -04:00 committed by GitHub
parent c954c2834a
commit 4d5521bbf7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -438,7 +438,12 @@ fn (mut s Scanner) ident_dec_number() string {
s.pos--
} else {
// 5.
s.warn('float literals should have a digit after the decimal point, e.g. `5.0`')
mut symbol_length := 0
for i := s.pos - 2; i > 0 && s.text[i - 1].is_digit(); i-- {
symbol_length++
}
float_symbol := s.text[s.pos - 2 - symbol_length..s.pos - 1]
s.warn('float literals should have a digit after the decimal point, e.g. `${float_symbol}.0`')
}
}
}

View File

@ -1,4 +1,4 @@
vlib/v/scanner/tests/float_literals_dot_err.vv:2:9: warning: float literals should have a digit after the decimal point, e.g. `5.0`
vlib/v/scanner/tests/float_literals_dot_err.vv:2:9: warning: float literals should have a digit after the decimal point, e.g. `1.0`
1 | fn main() {
2 | a := 1.
| ^