elm / compiler

Compiler for Elm, a functional language for reliable webapps.
https://elm-lang.org/
BSD 3-Clause "New" or "Revised" License
7.51k stars 656 forks source link

Compiler hangs and uses more and more memory on type error. #2214

Open ajmcmiddlin opened 3 years ago

ajmcmiddlin commented 3 years ago

Quick Summary: Compiler hangs and uses more and more memory on type error.

SSCCE

module Main exposing (..)

type alias Lens a b =
    { get : a -> b
    , set : b -> a -> a
    }

type alias Foo =
    { n : Int }

fooN : Lens Foo Int
fooN =
    Lens .n (\foo n -> { foo | n = n })

Additional Details

When I run elm make src/Main.elm the command never returns, and continues to use more and more memory until I kill the process.

The issue is with fooN, as the anonymous function used to define set has its parameters around the wrong way. If we change the definition to fooN = Lens .n (\n foo -> {foo | n = n}) then it compiles without error.

Additionally, if we simplify the Lens type definition to only include set, the compiler produces a type error and doesn't hang.

I originally encountered this using elm-monocle but have inlined the Lens definition to reproduce.

github-actions[bot] commented 3 years ago

Thanks for reporting this! To set expectations:

Finally, please be patient with the core team. They are trying their best with limited resources.

bitterjug commented 2 years ago

I ran into this very bug this week while using elm-monocle. Looking forward to a fix. But in the meantime I'll switch round the argument order of my getter :blush: