Skip to content

Commit 1423ff0

Browse files
committed
std/conv: fix ParseCmplx error may be invalid
1 parent f15e469 commit 1423ff0

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

std/conv/atoc.jule

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,14 @@
3737

3838
const fnParseCmplx = "ParseCmplx"
3939

40-
// convErr splits an error returned by parseFloatPrefix
41-
// into a syntax or range error for ParseCmplx.
42-
fn convErr(mut err: any, s: str): any {
40+
// Handles error returned by parseFloatPrefix for ParseCmplx.
41+
fn handleErr(mut err: any, s: str): any {
4342
mut x, ok := err.(&NumError)
4443
if ok {
4544
x.Func = fnParseCmplx
4645
x.Num = s
4746
}
48-
ret x
47+
ret err
4948
}
5049

5150
// Converts the string s to a complex number
@@ -84,7 +83,7 @@ fn ParseCmplx(mut s: str, bitSize: int)!: cmplx128 {
8483
// Read real part (possibly imaginary part if followed by 'i').
8584
mut re, mut n, mut err := parseFloatPrefix(s, size)
8685
if err != nil {
87-
throw convErr(err, orig)
86+
throw handleErr(err, orig)
8887
}
8988

9089
s = s[n:]
@@ -117,7 +116,7 @@ fn ParseCmplx(mut s: str, bitSize: int)!: cmplx128 {
117116
// Read imaginary part.
118117
im, n, err := parseFloatPrefix(s, size)
119118
if err != nil {
120-
throw convErr(err, orig)
119+
throw handleErr(err, orig)
121120
}
122121
s = s[n:]
123122
if s != "i" {

0 commit comments

Comments
 (0)