@@ -269,7 +269,7 @@ defmodule Module.Types.Apply do
269
269
270
270
case signature ( name , arity ) do
271
271
:none -> { dynamic ( ) , context }
272
- info -> apply_remote ( info , args_types , expr , stack , context )
272
+ info -> apply_remote ( nil , name , info , args_types , expr , stack , context )
273
273
end
274
274
end
275
275
@@ -287,10 +287,14 @@ defmodule Module.Types.Apply do
287
287
{ value_type , context }
288
288
289
289
:badtuple ->
290
- { error_type ( ) , badremote_error ( expr , [ integer ( ) , tuple ] , stack , context ) }
290
+ { error_type ( ) ,
291
+ badremote_error ( :erlang , :element , expr , [ integer ( ) , tuple ] , stack , context ) }
291
292
292
- reason ->
293
- { error_type ( ) , error ( { reason , expr , tuple , index - 1 , context } , meta , stack , context ) }
293
+ :badindex ->
294
+ mfac = mfac ( expr , :erlang , :element , 2 )
295
+
296
+ { error_type ( ) ,
297
+ error ( { :badindex , mfac , expr , tuple , index - 1 , context } , meta , stack , context ) }
294
298
end
295
299
end
296
300
@@ -308,10 +312,16 @@ defmodule Module.Types.Apply do
308
312
{ value_type , context }
309
313
310
314
:badtuple ->
311
- { error_type ( ) , badremote_error ( expr , [ integer ( ) , tuple , value ] , stack , context ) }
315
+ args_types = [ integer ( ) , tuple , value ]
316
+
317
+ { error_type ( ) ,
318
+ badremote_error ( :erlang , :insert_element , expr , args_types , stack , context ) }
312
319
313
- reason ->
314
- { error_type ( ) , error ( { reason , expr , tuple , index - 2 , context } , meta , stack , context ) }
320
+ :badindex ->
321
+ mfac = mfac ( expr , :erlang , :insert_element , 3 )
322
+
323
+ { error_type ( ) ,
324
+ error ( { :badindex , mfac , expr , tuple , index - 2 , context } , meta , stack , context ) }
315
325
end
316
326
end
317
327
@@ -322,10 +332,16 @@ defmodule Module.Types.Apply do
322
332
{ value_type , context }
323
333
324
334
:badtuple ->
325
- { error_type ( ) , badremote_error ( expr , [ integer ( ) , tuple ] , stack , context ) }
335
+ args_types = [ integer ( ) , tuple ]
336
+
337
+ { error_type ( ) ,
338
+ badremote_error ( :erlang , :delete_element , expr , args_types , stack , context ) }
326
339
327
- reason ->
328
- { error_type ( ) , error ( { reason , expr , tuple , index - 1 , context } , meta , stack , context ) }
340
+ :badindex ->
341
+ mfac = mfac ( expr , :erlang , :delete_element , 2 )
342
+
343
+ { error_type ( ) ,
344
+ error ( { :badindex , mfac , expr , tuple , index - 1 , context } , meta , stack , context ) }
329
345
end
330
346
end
331
347
@@ -340,7 +356,7 @@ defmodule Module.Types.Apply do
340
356
{ value_type , context }
341
357
342
358
:badnonemptylist ->
343
- { error_type ( ) , badremote_error ( expr , [ list ] , stack , context ) }
359
+ { error_type ( ) , badremote_error ( :erlang , :hd , expr , [ list ] , stack , context ) }
344
360
end
345
361
end
346
362
@@ -350,7 +366,7 @@ defmodule Module.Types.Apply do
350
366
{ value_type , context }
351
367
352
368
:badnonemptylist ->
353
- { error_type ( ) , badremote_error ( expr , [ list ] , stack , context ) }
369
+ { error_type ( ) , badremote_error ( :erlang , :tl , expr , [ list ] , stack , context ) }
354
370
end
355
371
end
356
372
@@ -405,30 +421,36 @@ defmodule Module.Types.Apply do
405
421
{ return ( boolean ( ) , args_types , stack ) , context }
406
422
end
407
423
408
- def remote ( mod , name , args_types , expr , stack , context ) do
424
+ def remote ( mod , fun , args_types , expr , stack , context ) do
409
425
arity = length ( args_types )
410
426
411
- case :elixir_rewrite . inline ( mod , name , arity ) do
412
- { mod , name } ->
413
- remote ( mod , name , args_types , expr , stack , context )
427
+ case :elixir_rewrite . inline ( mod , fun , arity ) do
428
+ { new_mod , new_fun } ->
429
+ expr = inline_meta ( expr , mod , fun )
430
+ remote ( new_mod , new_fun , args_types , expr , stack , context )
414
431
415
432
false ->
416
- { info , context } = signature ( mod , name , arity , elem ( expr , 1 ) , stack , context )
417
- apply_remote ( info , args_types , expr , stack , context )
433
+ { info , context } = signature ( mod , fun , arity , elem ( expr , 1 ) , stack , context )
434
+ apply_remote ( mod , fun , info , args_types , expr , stack , context )
418
435
end
419
436
end
420
437
421
- defp apply_remote ( info , args_types , expr , stack , context ) do
438
+ defp apply_remote ( mod , fun , info , args_types , expr , stack , context ) do
422
439
case apply_signature ( info , args_types , stack ) do
423
440
{ :ok , _indexes , type } ->
424
441
{ type , context }
425
442
426
443
{ :error , domain , clauses } ->
427
- error = { :badremote , expr , args_types , domain , clauses , context }
444
+ mfac = mfac ( expr , mod , fun , length ( args_types ) )
445
+ error = { :badremote , mfac , expr , args_types , domain , clauses , context }
428
446
{ error_type ( ) , error ( error , elem ( expr , 1 ) , stack , context ) }
429
447
end
430
448
end
431
449
450
+ defp inline_meta ( { node , meta , args } , mod , fun ) do
451
+ { node , [ inline: { mod , fun } ] ++ meta , args }
452
+ end
453
+
432
454
@ doc """
433
455
Returns the type of a remote capture.
434
456
"""
@@ -718,22 +740,28 @@ defmodule Module.Types.Apply do
718
740
error ( __MODULE__ , warning , meta , stack , context )
719
741
end
720
742
721
- defp badremote_error ( { { :. , _ , [ mod , fun ] } , meta , _ } = expr , args_types , stack , context ) do
722
- { _type , domain , [ { args , _ } | _ ] = clauses } = signature ( mod , fun , length ( args_types ) )
723
- error ( { :badremote , expr , args_types , domain || args , clauses , context } , meta , stack , context )
743
+ defp badremote_error ( mod , fun , { _ , meta , _ } = expr , args_types , stack , context ) do
744
+ arity = length ( args_types )
745
+ mfac = mfac ( expr , mod , fun , arity )
746
+ { _type , domain , [ { args , _ } | _ ] = clauses } = signature ( mod , fun , arity )
747
+ domain = domain || args
748
+ tuple = { :badremote , mfac , expr , args_types , domain , clauses , context }
749
+ error ( tuple , meta , stack , context )
724
750
end
725
751
726
- ## Diagnosstics
752
+ ## Diagnostics
727
753
728
- def format_diagnostic ( { :badindex , expr , type , index , context } ) do
754
+ def format_diagnostic ( { :badindex , mfac , expr , type , index , context } ) do
729
755
traces = collect_traces ( expr , context )
756
+ { mod , fun , arity , _converter } = mfac
757
+ mfa = Exception . format_mfa ( mod , fun , arity )
730
758
731
759
% {
732
760
details: % { typing_traces: traces } ,
733
761
message:
734
762
IO . iodata_to_binary ( [
735
763
"""
736
- expected a tuple with at least #{ pluralize ( index + 1 , "element" , "elements" ) } in #{ format_mfa ( expr ) } :
764
+ expected a tuple with at least #{ pluralize ( index + 1 , "element" , "elements" ) } in #{ mfa } :
737
765
738
766
#{ expr_to_string ( expr ) |> indent ( 4 ) }
739
767
@@ -778,10 +806,9 @@ defmodule Module.Types.Apply do
778
806
}
779
807
end
780
808
781
- def format_diagnostic ( { :badremote , expr , args_types , domain , clauses , context } ) do
809
+ def format_diagnostic ( { :badremote , mfac , expr , args_types , domain , clauses , context } ) do
782
810
traces = collect_traces ( expr , context )
783
- { { :. , _ , [ mod , fun ] } , _ , args } = expr
784
- { mod , fun , args , converter } = :elixir_rewrite . erl_to_ex ( mod , fun , args )
811
+ { mod , fun , arity , converter } = mfac
785
812
786
813
explanation =
787
814
empty_arg_reason ( converter . ( args_types ) ) ||
@@ -790,12 +817,15 @@ defmodule Module.Types.Apply do
790
817
#{ clauses_args_to_quoted_string ( clauses , converter ) }
791
818
"""
792
819
820
+ mfa_or_fa =
821
+ if mod , do: Exception . format_mfa ( mod , fun , arity ) , else: "#{ fun } /#{ arity } "
822
+
793
823
% {
794
824
details: % { typing_traces: traces } ,
795
825
message:
796
826
IO . iodata_to_binary ( [
797
827
"""
798
- incompatible types given to #{ Exception . format_mfa ( mod , fun , length ( args ) ) } :
828
+ incompatible types given to #{ mfa_or_fa } :
799
829
800
830
#{ expr_to_string ( expr ) |> indent ( 4 ) }
801
831
@@ -932,9 +962,19 @@ defmodule Module.Types.Apply do
932
962
defp pluralize ( 1 , singular , _ ) , do: "1 #{ singular } "
933
963
defp pluralize ( i , _ , plural ) , do: "#{ i } #{ plural } "
934
964
935
- defp format_mfa ( { { :. , _ , [ mod , fun ] } , _ , args } ) do
936
- { mod , fun , args , _ } = :elixir_rewrite . erl_to_ex ( mod , fun , args )
937
- Exception . format_mfa ( mod , fun , length ( args ) )
965
+ defp mfac ( { _ , [ inline: { mod , fun } ] ++ _ , _ } , _mod , _fun , arity ) do
966
+ { mod , fun , arity , & & 1 }
967
+ end
968
+
969
+ defp mfac ( { { :. , _ , [ mod , fun ] } , _ , args } , _mod , _fun , _arity )
970
+ when is_atom ( mod ) and is_atom ( fun ) do
971
+ { mod , fun , args , converter } = :elixir_rewrite . erl_to_ex ( mod , fun , args )
972
+ { mod , fun , length ( args ) , converter }
973
+ end
974
+
975
+ defp mfac ( _ , mod , fun , arity )
976
+ when is_atom ( mod ) and is_atom ( fun ) and is_integer ( arity ) do
977
+ { mod , fun , arity , & & 1 }
938
978
end
939
979
940
980
## Algebra helpers
0 commit comments