Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tag with invalid name compiles #7078

Open
BashkaMen opened this issue Sep 14, 2024 · 0 comments
Open

Tag with invalid name compiles #7078

BashkaMen opened this issue Sep 14, 2024 · 0 comments

Comments

@BashkaMen
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant