Shouldn't empty if .. do ..else blocks give a compilation error instead ?

42 views
Skip to first unread message

Mário Guimarães

unread,
Jun 24, 2020, 7:19:55 AM6/24/20
to elixir-lang-core
Hello,

I just observed the following cases

iex(3)> if true do
...(3)> else
...(3)> :ok
...(3)> end
nil
iex
(4)> if false do
...(4)> :ok
...(4)> else
...(4)> end
nil
iex
(5)> if :anything do
...(5)> else
...(5)> end
nil
iex
(6)>

Should't they give a compilation error instead due to the empty blocks?

Not only these cases are somewhat harder to read, but it seems that something is missing ...

Thanks

Andrea Leopardi

unread,
Jun 24, 2020, 11:16:12 AM6/24/20
to elixir-l...@googlegroups.com
It can't error out on compilation because it would be a breaking change. However, personally I'm not against a compilation warning here, but there's a chance we decided to not emit that for a reason that I can't recall right now 😅

Andrea

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-lang-co...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elixir-lang-core/81ee6358-695b-493d-aaf7-f310245943b6o%40googlegroups.com.

Mário Guimarães

unread,
Jun 24, 2020, 11:26:29 AM6/24/20
to elixir-lang-core
Ok, a warning is enough then, in case you cannot remember of a reason to not emit the warning :-)


quarta-feira, 24 de Junho de 2020 às 16:16:12 UTC+1, Andrea Leopardi escreveu:
It can't error out on compilation because it would be a breaking change. However, personally I'm not against a compilation warning here, but there's a chance we decided to not emit that for a reason that I can't recall right now 😅

Andrea
On Wed, 24 Jun 2020 at 13:19, Mário Guimarães <mario.lui...@gmail.com> wrote:
Hello,

I just observed the following cases

iex(3)> if true do
...(3)> else
...(3)> :ok
...(3)> end
nil
iex
(4)> if false do
...(4)> :ok
...(4)> else
...(4)> end
nil
iex
(5)> if :anything do
...(5)> else
...(5)> end
nil
iex
(6)>

Should't they give a compilation error instead due to the empty blocks?

Not only these cases are somewhat harder to read, but it seems that something is missing ...

Thanks

--
You received this message because you are subscribed to the Google Groups "elixir-lang-core" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elixir-l...@googlegroups.com.

Alessio 'Blaster' Biancalana

unread,
Jun 24, 2020, 11:28:55 AM6/24/20
to elixir-l...@googlegroups.com
Hi!
A warning would be great so one could watch on them using `mix compile --warnings-as-errors` :-)

Alessio

José Valim

unread,
Jun 24, 2020, 2:39:02 PM6/24/20
to elixir-l...@googlegroups.com
There are constructs that rely on this. For example, if you want to have a receive without clauses, only with an after, you would do:

receive do
after 30_000 -> IO.puts "waited 30s"
end


Alessio 'Blaster' Biancalana

unread,
Jun 24, 2020, 4:49:08 PM6/24/20
to elixir-l...@googlegroups.com
Hm, looks legit. Thanks for the explanation!

Alessio

Reply all
Reply to author
Forward
0 new messages