Hey , as the title says, I think I found a bug in Elm 0.19.
To understand why this baffled me, let me explain you what I did: I have finally found some time to update the codebase at Yodel from 0.18 to Elm 0.19.1 one app at a time. Some circular dependencies inside our apps and the big changes that happened in the 0.19 update blocked me until now (the first PR I started was in August 2018, but was never finished).
Ok, long story short, we have a module called ShortUUID
which allows us to convert (long) UUIDs like "64d7280f-736a-4ffa-b9c0-383f43486d0b"
to a shorter version ("DTEETeS5R2XxjrVTZxXoJS"
) back and forth. You can find it here. I converted the code to 0.19 and also switched from the unsupported hickscorp/elm-bigint
to the compatible cmditch/elm-bigint
. And my tests kept failing for an hour or so. I suspected the new BigInt
package and wanted to call it a day. And then I found the problem:
This is the working version:
encodeHelper : String -> BigInt -> String
encodeHelper output input =
if BigInt.gt input zero then
let
index =
input
|> BigInt.modBy abcLength
|> Maybe.map BigInt.toString
|> Maybe.andThen String.toInt
|> Maybe.withDefault 0
char =
abc
|> List.getAt index
|> Maybe.withDefault ' '
newInput =
BigInt.div input abcLength
newOutput =
String.cons char output
in
encodeHelper newOutput newInput
else
output
and this is the broken one:
encodeHelper : String -> BigInt -> String
encodeHelper output input =
if BigInt.gt input zero then
let
index =
newInput
|> BigInt.modBy abcLength
|> Maybe.map BigInt.toString
|> Maybe.andThen String.toInt
|> Maybe.withDefault 0
char =
abc
|> List.getAt index
|> Maybe.withDefault ' '
newInput =
BigInt.div input abcLength
newOutput =
String.cons char output
in
encodeHelper newOutput newInput
else
output
Do you see the difference? I used newInput
in the first index
assignment instead of just input
. And the compiler did not say a single word, which is very Elm-unlike.
newInput
is clearly defined below, and should in my opinion not be available above its definition.
My question now: Is this intended behavior or a bug in the Elm compiler?