@@ -195,7 +195,15 @@ defmodule Record do
195
195
Keyword . keyword? ( args ) ->
196
196
create ( atom , fields , args , caller )
197
197
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
199
207
end
200
208
end
201
209
@@ -291,7 +299,7 @@ defmodule Record do
291
299
[ _tag | values ] = Tuple . to_list ( record )
292
300
join_keyword ( fields , values , [ ] )
293
301
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 } "
295
303
raise ArgumentError , msg
296
304
end
297
305
end
0 commit comments