compiler icon indicating copy to clipboard operation
compiler copied to clipboard

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

Open ajmcmiddlin opened this issue 4 years ago • 2 comments

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 })
  • Elm: 0.19.1
  • Browser: NA
  • Operating System: Linux (NixOS 20.09 with kernel 5.4.119)

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.

ajmcmiddlin avatar Jul 23 '21 01:07 ajmcmiddlin

Thanks for reporting this! To set expectations:

  • Issues are reviewed in batches, so it can take some time to get a response.
  • Ask questions in a community forum. You will get an answer quicker that way!
  • If you experience something similar, open a new issue. We like duplicates.

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

github-actions[bot] avatar Jul 23 '21 01:07 github-actions[bot]

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:

bitterjug avatar Mar 15 '22 16:03 bitterjug