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
Elixir doesn't warn with trying to concat string literals with invalid operator and string interpolation #13496
Comments
Also confirmed this behavior exists in elixir 1.16.2 |
I may be wrong here, but my interpretation is: this warning comes from Erlang and only works for literals. Since the interpolated string isn't a literal in Erlang, the warning isn't raised there and then isn't translated by the Elixir compiler. |
I'm not sure how the compiler represents string interpolation internally (function call maybe?), but since it knows that the resulting type is a string, it should be smart enough to handle this case. If it's an OTP bug so be it, but I reckon the Elixir compiler can handle this |
@v0idpwn is correct.
I don't think this would qualify as a bug, as it is more in the realm of what a type-system like dialyzer is providing. |
Yes, and those warnings are not guaranteed. Nor Erlang nor Elixir compilers are attempting to find typing violations, those are rather found when trying to optimize code, and reported as a convenience. As mentioned above, those are rather addressed by type systems, Dialyzer, etc. :) |
We'll wait for the type system then 😀 FWIW, I was not aware than these warnings should be treated as a convenience, and even so the consistency is unexpected. If there's an opportunity to clarify this somewhere I think it would be helpful as this issue was inspired by code written by a newcomer to Elixir and only caught by an obscure dialyzer error |
Elixir and Erlang/OTP versions
Erlang/OTP 26 [erts-14.2.1] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [jit]
Elixir 1.16.0 (compiled with Erlang/OTP 26)
Operating system
MacOS
Current behavior
When compiling with
elixirc concat.ex
, I get the following warningnotice that it doesn't warn for
doesnt/1
. It seems that adding string interpolation breaks the check.Expected behavior
I would expect the same
ArithmeticError
warning fordoesnt/1
.The text was updated successfully, but these errors were encountered: