Skip to content

Commit

Permalink
v.scanner: fix string interpolation for float e format (fix #22429) (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
kbkpbot authored Dec 13, 2024
1 parent f048bb3 commit c941c3d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions vlib/v/scanner/scanner.v
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn (mut s Scanner) ident_dec_number() string {
}
// scan exponential part
mut has_exp := false
if s.pos < s.text.len && s.text[s.pos] in [`e`, `E`] {
if s.pos < s.text.len && s.text[s.pos] in [`e`, `E`] && !s.is_inside_string {
has_exp = true
s.pos++
if s.pos < s.text.len && s.text[s.pos] in [`-`, `+`] {
Expand Down Expand Up @@ -505,7 +505,7 @@ fn (mut s Scanner) ident_dec_number() string {
if !s.pref.translated {
s.error('this number has unsuitable digit `${first_wrong_digit.str()}`')
}
} else if s.text[s.pos - 1] in [`e`, `E`] {
} else if s.text[s.pos - 1] in [`e`, `E`] && !s.is_inside_string {
// error check: 5e
s.pos-- // adjust error position
s.error('exponent has no digits')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,10 @@ fn test_interpo_non_ascii_characters() {
hello := '你好'
assert '${hello},世界!' == '你好,世界!'
}

fn test_float_exponent_sign() {
a := 1234567.0123456e03
assert '${a:6.1e}' == '1.2e+09'
assert '${a:6.2e}' == '1.23e+09'
assert '${a:6.5e}' == '1.23457e+09'
}

0 comments on commit c941c3d

Please sign in to comment.