valderman / haste-compiler

A GHC-based Haskell to JavaScript compiler
http://haste-lang.org
BSD 3-Clause "New" or "Revised" License
1.45k stars 115 forks source link

JS syntax error caused by inlining #409

Closed phi16 closed 6 years ago

phi16 commented 6 years ago

Compiling the following source generates a syntax-error in JavaScript.

{-# INLINE f #-}
f :: Double
f = -1

x :: Double
x = read "1"

main :: IO ()
main = print $ 1 - f * x

The generated code contains var _kz=jsShow(1--1*E(_ky.a)); , which looks directly inlining the value f and resulting in an error in the expression 1--1*E(...). JS tells Uncaught ReferenceError: Invalid left-hand side expression in postfix operation, and Uncaught SyntaxError: Unexpected number in different case (seems to be the same cause.)

Note: the actual case is writing fromIntegral (floor e), which internally calls INLINEd function GHC.Float.RealFracMethods.floorDoubleInteger.

I'm using x86_64-windows-haste-0.5.5.1-ghc-7.10.2.

valderman commented 6 years ago

Huh, I thought this bug was squashed years ago. Good catch!