File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -492,8 +492,15 @@ impl Literal {
492492 Literal ( s. to_string ( ) )
493493 }
494494
495- pub fn float ( s : f64 ) -> Literal {
496- Literal ( s. to_string ( ) )
495+ pub fn float ( n : f64 ) -> Literal {
496+ if !n. is_finite ( ) {
497+ panic ! ( "Invalid float literal {}" , n) ;
498+ }
499+ let mut s = n. to_string ( ) ;
500+ if !s. contains ( '.' ) {
501+ s += ".0" ;
502+ }
503+ Literal ( s)
497504 }
498505
499506 pub fn integer ( s : i64 ) -> Literal {
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ fn symbols() {
1919fn literals ( ) {
2020 assert_eq ! ( Literal :: string( "foo" ) . to_string( ) , "\" foo\" " ) ;
2121 assert_eq ! ( Literal :: string( "\" " ) . to_string( ) , "\" \\ \" \" " ) ;
22+ assert_eq ! ( Literal :: float( 10.0 ) . to_string( ) , "10.0" ) ;
2223}
2324
2425#[ test]
You can’t perform that action at this time.
0 commit comments