roc icon indicating copy to clipboard operation
roc copied to clipboard

Compiler crash `invalid content in tag union variable ...`

Open OBenjaminT opened this issue 3 years ago • 3 comments

I was messing around with some roc code (I'm very new to this) in the zig example and the compiler crashed.

app "rocLovesZig"
    packages { pf: "main.roc" }
    imports []
    provides [main] to pf

main : Str
main =  RenderTree Node Data {text: "Ziggy Data!"}

RenderTree : Node -> Str
RenderTree = \node ->
    when node is
        Data load ->
            """
            \(load.text)
            """
        Link load ->
            """
            """
        Tag load ->
            """
            """

DataLoad : {text: Str}

LinkLoad : {}

TagLoad : {}

Node : [
    Data DataLoad,
    Link LinkLoad,
    Tag TagLoad,
]

Gives this:

$ roc build --no-link rocLovesZig.roc
thread '<unnamed>' panicked at 'invalid content in tag union variable: (74, Structure(Apply(`6.ItentID(0)`, SubSlice { start: 309, length: 0 })))', crates/compiler/mono/src/layout.rs:2564:23

I don't know if it's known or even what I'm doing wrong but I don't think it's supposed to be doing that...

OBenjaminT avatar Aug 16 '22 12:08 OBenjaminT

Thanks for the report! You're seeing this panic because roc build tries to compile the program even in the presence of type errors, which in this case has hit a code path the compiler didn't expect. If you run roc check first, you'll see some type errors:

── NAMING PROBLEM ────────────────────────────── examples/hello-world/main.roc ─

This annotation does not match the definition immediately following
it:

 9│>  RenderTree : Node -> Str
10│>  RenderTree = \node ->

Is it a typo? If not, put either a newline or comment between them.


── TYPE MISMATCH ─────────────────────────────── examples/hello-world/main.roc ─

Something is off with the body of the main definition:

6│  main : Str
7│  main =  RenderTree Node Data {text: "Ziggy Data!"}
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This RenderTree tag application has the type:

    [RenderTree [Node]a [Data]b { text : Str }]c

But the type annotation on main says it should be:

    Str

────────────────────────────────────────────────────────────────────────────────

The problem here is that Roc doesn't support variable names that are capitalized in their first character - the error message for that should be improved though. Also, Roc types are structural, so RenderTree Node Data {text: "Ziggy Data!"} should instead be renderTree (Data {text: "Ziggy Data!"}). With that your program should compile and execute correctly.

ayazhafiz avatar Aug 16 '22 13:08 ayazhafiz

Ah! I'm not used to that being an important factor, thanks.

I also didn't think it would be type errors because every other time I've run build it has told me about the type errors instead of compiling and crashing.

OBenjaminT avatar Aug 16 '22 14:08 OBenjaminT

yeah, the crash you see here is a compiler bug. Over the long term this should not be happening, and we'll need to fix it, but in the meantime, it is (unfortunately) a somewhat common occurrence.

ayazhafiz avatar Aug 16 '22 14:08 ayazhafiz