@@ -195,7 +195,15 @@ defmodule Record do
195195 Keyword . keyword? ( args ) ->
196196 create ( atom , fields , args , caller )
197197 true ->
198- quote do: Record . __keyword__ ( unquote ( atom ) , unquote ( fields ) , unquote ( args ) )
198+ case Macro . expand ( args , caller ) do
199+ { :{} , _ , [ ^ atom | list ] } when length ( list ) == length ( fields ) ->
200+ record = List . to_tuple ( [ atom | list ] )
201+ Macro . escape ( Record . __keyword__ ( atom , fields , record ) )
202+ { ^ atom , arg } when length ( fields ) == 1 ->
203+ Macro . escape ( Record . __keyword__ ( atom , fields , { atom , arg } ) )
204+ _ ->
205+ quote do: Record . __keyword__ ( unquote ( atom ) , unquote ( fields ) , unquote ( args ) )
206+ end
199207 end
200208 end
201209
@@ -291,7 +299,7 @@ defmodule Record do
291299 [ _tag | values ] = Tuple . to_list ( record )
292300 join_keyword ( fields , values , [ ] )
293301 else
294- msg = "expected argument to be a literal atom, literal keyword or a #{ atom } () record, got runtime: #{ inspect record } "
302+ msg = "expected argument to be a literal atom, literal keyword or a #{ inspect atom } record, got runtime: #{ inspect record } "
295303 raise ArgumentError , msg
296304 end
297305 end
0 commit comments