Skip to content

If-statement in body causes warning message #1

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

Closed
miaout17 opened this issue Feb 18, 2011 · 3 comments
Closed

If-statement in body causes warning message #1

miaout17 opened this issue Feb 18, 2011 · 3 comments

Comments

@miaout17
Copy link
Contributor

When running following code:

module Iftest
  def test
    if true
      IO.puts "if true works"
    else
      IO.puts "if true fails"
    end

    if false
      IO.puts "if false fails"
    else
      IO.puts "if false works"
    end
  end
end

Iftest.test

It works properly, but it causes some Erlang warning messages:

src/../play/iftest2.ex:3: this clause cannot match because of different types/sizes
src/../play/iftest2.ex:9: this clause cannot match because of different types/sizes

However, if the if-statement is not in a function body, the warning message is not shown:

if true
  IO.puts "if true works"
else
  IO.puts "if true fails"
end

if false
  IO.puts "if false fails"
else
  IO.puts "if false works"
end

Sample code is available at my repository:

@josevalim
Copy link
Member

The second one never raises warnings because it is never compiled, just executed. :) I have just pushed a fix, thanks for reporting!

@josevalim
Copy link
Member

Ignore nomatch_clause_type warnings, closed by 02b7339

@knewter
Copy link

knewter commented Jan 31, 2015

wow accidentally got pointed here by typing "#1" in IRC. Syntax blast from a past I was not involved in :)

josevalim added a commit that referenced this issue Jul 2, 2024
Rule #1:

    Enum.reverse([1, 2, 3]) ++ [4, 5, 6]

is equivalent but slower than

    Enum.reverse([1, 2, 3], [4, 5, 6])

Rule #2:

    Enum.reverse([1, 2, 3] ++ [4, 5, 6])

is equivalent but slower than:

    Enum.reverse([4, 5, 6], Enum.reverse([1, 2, 3]))

Rule #3

    Enum.reverse(Enum.reverse([1, 2, 3]))

is the same as:

    [1, 2, 3]
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants