roc-lang / roc

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

Tag with invalid name compiles #7078

Open BashkaMen opened 2 months ago

BashkaMen commented 2 months ago

I expected to get an error because tokenize : Str -> [EmptyStr, NotEmptyStr Str]

app [main] {
    pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.15.0/SlwdbJ-3GR7uBWQo6zlmYWNYOxnvo8r6YABXD-45UOw.tar.br",
}

import pf.Stdout
import pf.Stdin

tokenize = \x -> if Str.isEmpty x then EmptyStr else NotEmptyStr x
expect tokenize "" == EmptyStr
expect tokenize "man" == NotEmptyStr "man"

parse = \input ->
    when input is
        "" -> []
        _ -> input |> Str.split " " |> List.map tokenize

expect parse "hello man" == [NotEmptyStr "hello", NotEmptyStr "man"]
expect parse "" == []

parseOne =
    when tokenize "man" is
        EmptyStr -> "work correct"
        NotEmptyStr x -> "word correct $(x)"
        INVALIDNAME -> "invalid case????"

main =
    Stdout.line! parseOne

if we add this code and run (roc test) it we will get an error

parseInput = \input ->
    parsed = parse input
    dbg parsed

    when parsed is
        [NotEmptyStr "say-hello", INVALIDTAGNAME name] -> SayHello name
        _ -> InvalidCmd "invalid cmd name"

expect parseInput "invalid cmd" == InvalidCmd "invalid cmd name"
expect parseInput "say-hello dima" == SayHello "dima"
thread '<unnamed>' panicked at crates/compiler/mono/src/ir.rs:6151:56:
called `Option::unwrap()` on a `None` value
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace