Elixir: Raise better error message for unknown local | in pattern

Created on 10 Oct 2017  路  8Comments  路  Source: elixir-lang/elixir

For example in cases such as:

defp comparison(left_head | left_tail, [], result \\ "") do

Or alternatively we can improve unknown | altogether, even outside of patterns.

Elixir Chore Intermediate Discussion

Most helpful comment

@josevalim How about this one?

Misused operator `|` in function definition at {file}:{line}:

  defp comparison(left_head [red]|[/red] left_tail, [], result \\ "") do

If you were trying to match on list head and tail, you need to wrap this expression with square brackets. See more at https://elixir-lang.org/getting-started/pattern-matching.html.

And similar for ::.

All 8 comments

What is the error in your given example? It looks like normal [head|tail] matching?

Or is this for when the | operator is overridden?

Oops, I have updated the example. It will say unknown function | and we can provide some pointers. The same for ::.

Ah, makes much more sense! ^.^

If you're okay with it, I'd like to see if I can take it, but I need more hints to start, I'm a newcomer.

Thanks!

@dsantosmerino the tricky part on this one is not the implementation but writing the error message and I still do not know how that should look like. If anyone has suggestions, please let us know.

@josevalim what if I redefine my own | operator which is not context-dependent?

@whatyouhide we will only raise if there is no overriding (that's already how it works btw, we are just improving the message for certain cases).

@josevalim How about this one?

Misused operator `|` in function definition at {file}:{line}:

  defp comparison(left_head [red]|[/red] left_tail, [], result \\ "") do

If you were trying to match on list head and tail, you need to wrap this expression with square brackets. See more at https://elixir-lang.org/getting-started/pattern-matching.html.

And similar for ::.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jdeisenberg picture jdeisenberg  路  4Comments

andrewcottage picture andrewcottage  路  3Comments

josevalim picture josevalim  路  3Comments

whitepaperclip picture whitepaperclip  路  3Comments

vothane picture vothane  路  3Comments