-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Unexpected results in otp 26 #9476
Comments
Hello! This is not a bug in Erlang, but a bug in your code. The only input to b(Data) ->
F =
fun(Map) ->
{
maps:get(a, Map, 0),
maps:get(b, Map, 0)
}
end,
#abc{data = maps:from_list(lists:map(F, Data))}. If you need more help understanding the Erlang and its APIs, please visit the https://www.erlangforums.com and people there will be happy to answer your questions. |
i know,but when data is empty list,why can't return #abc{} or report error, |
Aha, now I see what you mean! Yes, that is indeed a bug. The compiler seems to assume that the call to lists:map/2 will fail becase the fun will never return a correct value, but when called with the empty list it never calls the fun and thus does not fail. |
Thanks for reporting this, I've fixed it in #9481 :) |
Describe the bug
Unexpected results
To Reproduce
Expected behavior
why ach:b([]). return #{} not return #abc{}
Alternatively, an error can be reported instead of receiving unexpected results
Affected versions
Erlang/OTP 26 [erts-14.2.5.4]
Additional context
Add any other context about the problem here. If you wish to attach Erlang code you can either write it directly in the post using code tags, create a gist, or attach it as a zip file to this post.
The text was updated successfully, but these errors were encountered: