Skip to content

Commit

Permalink
kernel: raise error if eager float literal conversion fails
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Apr 17, 2018
1 parent 6f6131d commit 7b7e592
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/intrprtr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1804,7 +1804,10 @@ static Obj ConvertFloatLiteralEager(Obj str)
SET_LEN_STRING(str, len - 2);
chars[len - 2] = '\0';
}
return CALL_2ARGS(CONVERT_FLOAT_LITERAL_EAGER, str, ObjsChar[(UInt)mark]);
Obj res = CALL_2ARGS(CONVERT_FLOAT_LITERAL_EAGER, str, ObjsChar[(UInt)mark]);
if (res == Fail)
ErrorQuit("failed to convert float literal", 0, 0);
return res;
}

void IntrFloatExpr (
Expand Down
21 changes: 21 additions & 0 deletions tst/testinstall/float.tst
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,27 @@ false
gap> EqFloat(0.0,0.0/0.0);
false

#
# float literals in the REPL
#
gap> 1.1;
1.1
gap> 1.1_;
1.1
gap> 1.x1;
Syntax error: Badly formed number in stream:1
1.x1;
^
gap> 1.1xx;
Syntax error: Badly formed number in stream:1
1.1xx;
^

# The following is potentially correct, *if* there is a conversion handler for
# 'x' installed, which normally isn't the case.
gap> 1.1x;
Error, failed to convert float literal

#
# float literal expressions in functions
#
Expand Down
2 changes: 1 addition & 1 deletion tst/testinstall/longnumber.tst
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ int in stream:1
.q;
^
gap> .0n;
fail
Error, failed to convert float literal
gap> .0q;
Syntax error: Badly Formed Number: need at least one digit in the exponent in \
stream:1
Expand Down

0 comments on commit 7b7e592

Please sign in to comment.