Skip to content

Unexpected results in otp 26 #9476

Open
@WHYZN

Description

Describe the bug
Unexpected results

To Reproduce

-module(abc).

%% API
-export([a/1, b/1]).

-record(abc, {data}).

-record(kv, {k, v}).

a(Data) ->
	F =
		fun(Map) ->
			{maps:get(a, Map, 0),
				#kv{
					k = maps:get(a, Map, 0),
					v = maps:get(b, Map, 0)
				}}
		end,
	
	#abc{data = maps:from_list(lists:map(F, Data))}.

b(Data) ->
	F =
		fun(Map) ->
			#kv{
				k = maps:get(a, Map, 0),
				v = maps:get(b, Map, 0)
			}
		end,
	#abc{data = maps:from_list(lists:map(F, Data))}.

Expected behavior

(game_ccc_1@127.0.0.1)24> Data = [#{a => 1, b => 2}, #{a => 3, b => 4}].
[#{a => 1,b => 2},#{a => 3,b => 4}]
(game_ccc_1@127.0.0.1)25> abc:a(Data).
{abc,#{1 => {kv,1,2},3 => {kv,3,4}}}
(game_ccc_1@127.0.0.1)26> abc:b([]).
#{}
(game_ccc_1@127.0.0.1)27> abc:b(Data).
* exception error: bad argument
in function  maps:from_list/1
called as maps:from_list([{kv,1,2},{kv,3,4}])
in call from abc:b/1 (apps/mmo_server/src/role/abc.erl, line 43)

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions