#Type checker requires `assert`, but then throws a warning about the compiled code

1 messages · Page 1 of 1 (latest)

rain breach
#

This is not a bug per se, I think, but maybe it's something that's worth taking a look at.

I have a type with two constructors, Global and Local. At one point, I do this:

let Global(table: new_table) as new_env = Global(map.insert(into: table, for: name, insert: value))

As it is, gleam complains that new_env could be a Local instead of a Global. I mean, the r-value is explicitly a Global, but okay - I change it to

let assert Global(table: new_table) as new_env = Global(map.insert(into: table, for: name, insert: value)).

Now, when it compiles, Erlang gives a warning:

    _assert_subject = {global, gleam@map:insert(Table, Name, Value)},
    {global, New_table} = New_env = case _assert_subject of
        {global, _} -> _assert_subject;
        _assert_fail -> erlang:error(#{gleam_error => let_assert etc etc etc})

The warning says the _assert_fail clause cannot match because the previous one always matches... there's a redundancy here that's slightly annoying. This particular case is not high-priority, but hopefully the type checker will improve in the future and make this assert unnecessary? 😄

hallow pebble
#

I have a type with two constructors, Global and Local. At one point, I do this:

let Global(table: new_table) as new_env = Global(map.insert(into: table, for: name, insert: value))

but why

#

i assume you're leaving out some context as to why you're doing this but that aside

#

its possible in the future the compiler could refine types like this but there's no immediate plans for it

potent comet
#

Could we see the rest of the code?

uneven flint
#

like, why not write

let new_table = map.insert(into: table, for: name, insert: value)
let new_env = Global(new_table)
misty cedar
#

code is in #1047101890707603547 btw

rain breach
#

In the end this code was not doing what I wanted it to, so I removed it. Sorry for the bother 😦 thank you all anyway

misty cedar
#

Well it's still good to note that this is possible and produces something a bit unexpected