我是靠谱客的博主 炙热方盒,最近开发中收集的这篇文章主要介绍Erlang笔记(13) - Erlang 编译错误,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  • module.beam: Module name 'madule' does not match file name 'module'
  • The module name you’ve entered in the -module attribute doesn’t match the filename.

  • ./module.erl:2: Warning: function some_function/0 is unused
  • You have not exported a function, or the place where it’s used has thewrong name or arity. It’s also possible you’ve written a function that isno longer needed. Check your code!

  • ./module.erl:2: function some_function/1 undefined
  • The function does not exist. You’ve written the wrong name or arity either in the -export attribute or when declaring the function. This error is also output when the given function could not be compiled, usually because of a syntax error like forgetting to end a function with a period.

  • ./module.erl:5: syntax error before: 'SomeCharacterOrWord'
  • This happens for a variety of reasons. Common causes are unclosed parentheses, tuples, or wrong expression termination (like closing the last branch of a case with a comma). Other reasons include the use of a reserved atom in your code and Unicode characters not being con-verted correctly between different encodings (I’ve seen it happen!).

  • ./module.erl:5: syntax error before:
  • This message is certainly not as descriptive as the previous one. It usually comes up when your line termination is not correct. This is a specific case of the previous error, so just keep an eye out.

  • ./module.erl:5: Warning: this expression will fail with a 'badarith' exception
  • Erlang is all about dynamic typing, but remember that the types are strong. In this case, the compiler is smart enough to find that one of your arithmetic expressions will fail (say, llama + 5). It won’t find type errors much more complex than that, though.

  • ./module.erl:5: Warning: variable 'Var' is unused
  • You declared a variable and never used it. This might be a bug with your code, so double-check what you have written. Otherwise, you might want to switch the variable name to _, or just prefix it with an underscore if you feel the name helps make the code readable.

  • ./module.erl:5: Warning: a term is constructed, but never used
  • In one of your functions, you’re doing something such as building a list, or declaring a tuple or an anonymous function without ever binding it to a variable or returning it. This warning tells you that you’re doing something useless or have made some mistake.

  • ./module.erl:5: head mismatch
  • It’s possible your function has more than one head, and each of them has a different arity. Don’t forget that different arity means different functions, and you can’t interleave function declarations that way.
  • Similarly, this error is raised when you insert a function definition between the head clauses of another function.

  • ./module.erl:5: Warning: this clause cannot match because a previous clause at
  • line 4 always matches
  • A function defined in the module has a specific clause defined after a catchall one. As such, the compiler can warn you that you’ll never even need to go to the other branch.

  • ./module.erl:9: variable 'A' unsafe in 'case' (line 5)
  • You’re using a variable declared within one of the branches of a case ... of outside of it. This is considered unsafe. If you want to use such variables, you’re better off doing MyVar = case ... of.

最后

以上就是炙热方盒为你收集整理的Erlang笔记(13) - Erlang 编译错误的全部内容,希望文章能够帮你解决Erlang笔记(13) - Erlang 编译错误所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(57)

评论列表共有 0 条评论

立即
投稿
返回
顶部