roc-lang / roc

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

Type mismatches with Result should not show `Ok` and `Err` on one side and `Result` on the other #6957

Open Anton-4 opened 3 months ago

Anton-4 commented 3 months ago

This should show Result on both sides:

── TYPE MISMATCH in examples/helloWorld.roc ────────────────────────────────────

Something is off with the then branch of this if expression:

6│  myResult: U64 -> Result Str [TooSmall]
7│  myResult = \x ->
8│      if x > 5 then
9│          Ok ["large enough!"]
            ^^^^^^^^^^^^^^^^^^^^

This Ok tag application has the type:

    [
        Err [TooSmall],
        Ok (List Str),
    ]

But the type annotation on myResult says it should be:

    Result Str [TooSmall]

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

Code to produce the error:

app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }

import pf.Stdout
import pf.Task

myResult: U64 -> Result Str [TooSmall]
myResult = \x ->
    if x > 5 then
        Ok ["large enough!"]
    else
        Err TooSmall

main =
    Stdout.line! (Inspect.toStr (myResult 6))