Skip to content

Compiler bug: "? [rank = 1]" in Type/Solve.hs #2153

Open
@ianmackenzie

Description

@ianmackenzie

I ran into a compiler bug when attempting to 'genericize' some code; basically I have a function that accepts a List Point2d and I wanted to convert it into a function that accepts a List vertex, by supplying a vertex -> Point2d function. I worked the code down to as small as an SSCCE as I could, switching to primitive types in the process.

SSCCE

If I attempt to compile

module CompilerTest exposing (foo)


foo : (a -> String) -> List a -> Maybe String
foo toString items =
    case items of
        firstItem :: remainingItems ->
            fooHelp toString (toString firstItem) remainingItems

        _ ->
            Nothing


fooHelp : (a -> String) -> String -> List a -> Maybe String
fooHelp toString firstString currentItems =
    case currentItems of
        firstItem :: remainingItems ->
            fooHelp toString firstItem remainingItems

        [] ->
            Nothing

I get

Compiling ...elm: You ran into a compiler bug. Here are some details for the developers:

    ? [rank = 1]

Please create an <http://sscce.org/> and then report it
at <https://github.com/elm/compiler/issues>


CallStack (from HasCallStack):
  error, called at compiler/src/Type/Solve.hs:206:15 in main:Type.Solve

-- ERROR -----------------------------------------------------------------------

I ran into something that bypassed the normal error reporting process! I
extracted whatever information I could from the internal error:

>   thread blocked indefinitely in an MVar operation

The bug in the code is that the recursive fooHelp call is missing a toString call; it should be

fooHelp toString (toString firstItem) remainingItems

like it is in foo, and if it is changed to that the code compiles fine.

  • Elm: 0.19.1
  • Browser: N/A
  • Operating System: Tested on Windows and Linux (WSL 2)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions