roc-lang / roc

A fast, friendly, functional language.
https://roc-lang.org
Universal Permissive License v1.0
4.4k stars 309 forks source link

Monomorphization panic for composed tag unions #2365

Closed rtfeldman closed 2 years ago

rtfeldman commented 2 years ago

03098d4096135fe53f8da5d0ec2d9607d7b13979 has no type mismatches reported in roc check but causes a panic in layout.rs: assertion failed: ext_var_is_empty_tag_union(subs, ext_var)', compiler/mono/src/layout.rs:1538:13

The diff here is:

-        Err readErr -> Task.succeed "" #Task.fail readErr
+        Err readErr -> Task.fail readErr

The Err readErr was returned by this function:

readBytes : Path -> Task (List U8) (ReadErr *)

However, the function with the Err readErr -> Task.fail readErr in it does not return a ReadErr * like readBytes does. Instead it returns this:

readUtf8 : Path -> Task Str (ReadUtf8Err *)

The reason this isn't a type mismatch is that ReadUtf8Err is actually a superset of ReadErr:

ReadUtf8Err a : ReadErr [ BadUtf8 Path Str.Utf8ByteProblem Nat ]a

ReadErr a :
    [
        FileBusy Path,
        FileWasDir Path,
        IllegalByteSequence Path,
        InvalidSeek Path,
    ]a

So although it type-checks, it doesn't compile due to a layout error.

rtfeldman commented 2 years ago

This is blocking https://github.com/rtfeldman/roc/pull/2105

ayazhafiz commented 2 years ago

Applying 8acab97 appears to fix this:

$ cargo run -- examples/cli/Files.roc
    Finished dev [unoptimized + debuginfo] target(s) in 0.39s
     Running `target/debug/roc examples/cli/Files.roc`
🔨 Rebuilding host...
── UNUSED DEFINITION ───────────────────────────────────────────────────────────

index is not used anywhere in your code.

83│                  Err (BadUtf8 problem index) -> Task.succeed ""
                                          ^^^^^

If you didn't intend on using index then remove it so future readers
of your code don't wonder why it is there.

── UNUSED DEFINITION ───────────────────────────────────────────────────────────

problem is not used anywhere in your code.

83│                  Err (BadUtf8 problem index) -> Task.succeed ""
                                  ^^^^^^^

If you didn't intend on using problem then remove it so future readers
of your code don't wonder why it is there.

── UNUSED IMPORT ───────────────────────────────────────────────────────────────

Nothing from Stdout is used in this module.

3│      imports [ fx.Effect, Task.{ Task }, Stdout ]
                                            ^^^^^^

Since Stdout isn't used, you don't need to import it.

── UNUSED IMPORT ───────────────────────────────────────────────────────────────

Nothing from File is used in this module.

5│      imports [ Task.{ Task }, File.{ ReadErr, ReadErrTag, ReadUtf8Err } ]
                                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Since File isn't used, you don't need to import it.

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

Done!
What file should I read?