@@ -385,17 +385,17 @@ defmodule Kernel.Typespec do
385
385
compile_error ( caller , error )
386
386
end
387
387
388
- line = line ( meta )
388
+ location = location ( meta )
389
389
vars = Keyword . keys ( guard )
390
390
391
391
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
392
392
{ return , state } = typespec ( return , vars , caller , state )
393
- spec = { :type , line , :fun , [ { :type , line , :product , args } , return ] }
393
+ spec = { :type , location , :fun , [ { :type , location , :product , args } , return ] }
394
394
395
395
{ spec , state } =
396
396
case guard_to_constraints ( guard , vars , meta , caller , state ) do
397
397
{ [ ] , state } -> { spec , state }
398
- { constraints , state } -> { { :type , line , :bounded_fun , [ spec , constraints ] } , state }
398
+ { constraints , state } -> { { :type , location , :bounded_fun , [ spec , constraints ] } , state }
399
399
end
400
400
401
401
ensure_no_unused_local_vars! ( caller , state . local_vars )
@@ -437,17 +437,17 @@ defmodule Kernel.Typespec do
437
437
defp ensure_not_default ( _ ) , do: :ok
438
438
439
439
defp guard_to_constraints ( guard , vars , meta , caller , state ) do
440
- line = line ( meta )
440
+ location = location ( meta )
441
441
442
442
fun = fn
443
443
{ _name , { :var , _ , context } } , { constraints , state } when is_atom ( context ) ->
444
444
{ constraints , state }
445
445
446
446
{ name , type } , { constraints , state } ->
447
447
{ spec , state } = typespec ( type , vars , caller , state )
448
- constraint = [ { :atom , line , :is_subtype } , [ { :var , line , name } , spec ] ]
448
+ constraint = [ { :atom , location , :is_subtype } , [ { :var , location , name } , spec ] ]
449
449
state = update_local_vars ( state , name )
450
- { [ { :type , line , :constraint , constraint } | constraints ] , state }
450
+ { [ { :type , location , :constraint , constraint } | constraints ] , state }
451
451
end
452
452
453
453
{ constraints , state } = :lists . foldl ( fun , { [ ] , state } , guard )
@@ -456,21 +456,27 @@ defmodule Kernel.Typespec do
456
456
457
457
## To typespec conversion
458
458
459
- defp line ( meta ) do
460
- Keyword . get ( meta , :line , 0 )
459
+ defp location ( meta ) do
460
+ line = Keyword . get ( meta , :line , 0 )
461
+
462
+ if column = Keyword . get ( meta , :column ) do
463
+ { line , column }
464
+ else
465
+ line
466
+ end
461
467
end
462
468
463
469
# Handle unions
464
470
defp typespec ( { :| , meta , [ _ , _ ] } = exprs , vars , caller , state ) do
465
471
exprs = collect_union ( exprs )
466
472
{ union , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , exprs )
467
- { { :type , line ( meta ) , :union , union } , state }
473
+ { { :type , location ( meta ) , :union , union } , state }
468
474
end
469
475
470
476
# Handle binaries
471
477
defp typespec ( { :<<>> , meta , [ ] } , _ , _ , state ) do
472
- line = line ( meta )
473
- { { :type , line , :binary , [ { :integer , line , 0 } , { :integer , line , 0 } ] } , state }
478
+ location = location ( meta )
479
+ { { :type , location , :binary , [ { :integer , location , 0 } , { :integer , location , 0 } ] } , state }
474
480
end
475
481
476
482
defp typespec (
@@ -480,14 +486,18 @@ defmodule Kernel.Typespec do
480
486
state
481
487
)
482
488
when is_atom ( ctx1 ) and is_atom ( ctx2 ) and unit in 1 .. 256 do
483
- line = line ( meta )
484
- { { :type , line , :binary , [ { :integer , line , 0 } , { :integer , line ( unit_meta ) , unit } ] } , state }
489
+ location = location ( meta )
490
+
491
+ { { :type , location , :binary , [ { :integer , location , 0 } , { :integer , location ( unit_meta ) , unit } ] } ,
492
+ state }
485
493
end
486
494
487
495
defp typespec ( { :<<>> , meta , [ { :"::" , size_meta , [ { :_ , _ , ctx } , size ] } ] } , _ , _ , state )
488
496
when is_atom ( ctx ) and is_integer ( size ) and size >= 0 do
489
- line = line ( meta )
490
- { { :type , line , :binary , [ { :integer , line ( size_meta ) , size } , { :integer , line , 0 } ] } , state }
497
+ location = location ( meta )
498
+
499
+ { { :type , location , :binary , [ { :integer , location ( size_meta ) , size } , { :integer , location , 0 } ] } ,
500
+ state }
491
501
end
492
502
493
503
defp typespec (
@@ -505,8 +515,8 @@ defmodule Kernel.Typespec do
505
515
)
506
516
when is_atom ( ctx1 ) and is_atom ( ctx2 ) and is_atom ( ctx3 ) and is_integer ( size ) and
507
517
size >= 0 and unit in 1 .. 256 do
508
- args = [ { :integer , line ( size_meta ) , size } , { :integer , line ( unit_meta ) , unit } ]
509
- { { :type , line ( meta ) , :binary , args } , state }
518
+ args = [ { :integer , location ( size_meta ) , size } , { :integer , location ( unit_meta ) , unit } ]
519
+ { { :type , location ( meta ) , :binary , args } , state }
510
520
end
511
521
512
522
defp typespec ( { :<<>> , _meta , _args } , _vars , caller , _state ) do
@@ -519,25 +529,25 @@ defmodule Kernel.Typespec do
519
529
520
530
## Handle maps and structs
521
531
defp typespec ( { :map , meta , args } , _vars , _caller , state ) when args == [ ] or is_atom ( args ) do
522
- { { :type , line ( meta ) , :map , :any } , state }
532
+ { { :type , location ( meta ) , :map , :any } , state }
523
533
end
524
534
525
535
defp typespec ( { :%{} , meta , fields } = map , vars , caller , state ) do
526
536
fun = fn
527
537
{ { :required , meta2 , [ k ] } , v } , state ->
528
538
{ arg1 , state } = typespec ( k , vars , caller , state )
529
539
{ arg2 , state } = typespec ( v , vars , caller , state )
530
- { { :type , line ( meta2 ) , :map_field_exact , [ arg1 , arg2 ] } , state }
540
+ { { :type , location ( meta2 ) , :map_field_exact , [ arg1 , arg2 ] } , state }
531
541
532
542
{ { :optional , meta2 , [ k ] } , v } , state ->
533
543
{ arg1 , state } = typespec ( k , vars , caller , state )
534
544
{ arg2 , state } = typespec ( v , vars , caller , state )
535
- { { :type , line ( meta2 ) , :map_field_assoc , [ arg1 , arg2 ] } , state }
545
+ { { :type , location ( meta2 ) , :map_field_assoc , [ arg1 , arg2 ] } , state }
536
546
537
547
{ k , v } , state ->
538
548
{ arg1 , state } = typespec ( k , vars , caller , state )
539
549
{ arg2 , state } = typespec ( v , vars , caller , state )
540
- { { :type , line ( meta ) , :map_field_exact , [ arg1 , arg2 ] } , state }
550
+ { { :type , location ( meta ) , :map_field_exact , [ arg1 , arg2 ] } , state }
541
551
542
552
{ :| , _ , [ _ , _ ] } , _state ->
543
553
error =
@@ -551,7 +561,7 @@ defmodule Kernel.Typespec do
551
561
end
552
562
553
563
{ fields , state } = :lists . mapfoldl ( fun , state , fields )
554
- { { :type , line ( meta ) , :map , fields } , state }
564
+ { { :type , location ( meta ) , :map , fields } , state }
555
565
end
556
566
557
567
defp typespec ( { :% , _ , [ name , { :%{} , meta , fields } ] } = node , vars , caller , state ) do
@@ -644,7 +654,7 @@ defmodule Kernel.Typespec do
644
654
{ right , state } = typespec ( right , vars , caller , state )
645
655
:ok = validate_range ( left , right , caller )
646
656
647
- { { :type , line ( meta ) , :range , [ left , right ] } , state }
657
+ { { :type , location ( meta ) , :range , [ left , right ] } , state }
648
658
end
649
659
650
660
# Handle special forms
@@ -668,7 +678,7 @@ defmodule Kernel.Typespec do
668
678
pair -> pair
669
679
end
670
680
671
- { { :type , line ( meta ) , :fun , fun_args } , state }
681
+ { { :type , location ( meta ) , :fun , fun_args } , state }
672
682
end
673
683
674
684
# Handle type operator
@@ -691,10 +701,10 @@ defmodule Kernel.Typespec do
691
701
# This may be generating an invalid typespec but we need to generate it
692
702
# to avoid breaking existing code that was valid but only broke Dialyzer
693
703
{ right , state } = typespec ( expr , vars , caller , state )
694
- { { :ann_type , line ( meta ) , [ { :var , line ( var_meta ) , var_name } , right ] } , state }
704
+ { { :ann_type , location ( meta ) , [ { :var , location ( var_meta ) , var_name } , right ] } , state }
695
705
696
706
{ right , state } ->
697
- { { :ann_type , line ( meta ) , [ { :var , line ( var_meta ) , var_name } , right ] } , state }
707
+ { { :ann_type , location ( meta ) , [ { :var , location ( var_meta ) , var_name } , right ] } , state }
698
708
end
699
709
end
700
710
@@ -723,13 +733,13 @@ defmodule Kernel.Typespec do
723
733
{ left , state } = typespec ( left , vars , caller , state )
724
734
state = % { state | undefined_type_error_enabled?: true }
725
735
{ right , state } = typespec ( right , vars , caller , state )
726
- { { :ann_type , line ( meta ) , [ left , right ] } , state }
736
+ { { :ann_type , location ( meta ) , [ left , right ] } , state }
727
737
end
728
738
729
739
# Handle unary ops
730
740
defp typespec ( { op , meta , [ integer ] } , _ , _ , state ) when op in [ :+ , :- ] and is_integer ( integer ) do
731
- line = line ( meta )
732
- { { :op , line , op , { :integer , line , integer } } , state }
741
+ location = location ( meta )
742
+ { { :op , location , op , { :integer , location , integer } } , state }
733
743
end
734
744
735
745
# Handle remote calls in the form of @module_attribute.type.
@@ -778,12 +788,12 @@ defmodule Kernel.Typespec do
778
788
779
789
# Handle tuples
780
790
defp typespec ( { :tuple , meta , [ ] } , _vars , _caller , state ) do
781
- { { :type , line ( meta ) , :tuple , :any } , state }
791
+ { { :type , location ( meta ) , :tuple , :any } , state }
782
792
end
783
793
784
794
defp typespec ( { :{} , meta , t } , vars , caller , state ) when is_list ( t ) do
785
795
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , t )
786
- { { :type , line ( meta ) , :tuple , args } , state }
796
+ { { :type , location ( meta ) , :tuple , args } , state }
787
797
end
788
798
789
799
defp typespec ( { left , right } , vars , caller , state ) do
@@ -799,7 +809,7 @@ defmodule Kernel.Typespec do
799
809
defp typespec ( { name , meta , atom } , vars , caller , state ) when is_atom ( atom ) do
800
810
if :lists . member ( name , vars ) do
801
811
state = update_local_vars ( state , name )
802
- { { :var , line ( meta ) , name } , state }
812
+ { { :var , location ( meta ) , name } , state }
803
813
else
804
814
typespec ( { name , meta , [ ] } , vars , caller , state )
805
815
end
@@ -814,7 +824,7 @@ defmodule Kernel.Typespec do
814
824
815
825
IO . warn ( warning , caller )
816
826
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
817
- { { :type , line ( meta ) , :string , args } , state }
827
+ { { :type , location ( meta ) , :string , args } , state }
818
828
end
819
829
820
830
defp typespec ( { :nonempty_string , meta , args } , vars , caller , state ) do
@@ -825,7 +835,7 @@ defmodule Kernel.Typespec do
825
835
826
836
IO . warn ( warning , caller )
827
837
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
828
- { { :type , line ( meta ) , :nonempty_string , args } , state }
838
+ { { :type , location ( meta ) , :nonempty_string , args } , state }
829
839
end
830
840
831
841
defp typespec ( { type , _meta , [ ] } , vars , caller , state ) when type in [ :charlist , :char_list ] do
@@ -855,7 +865,7 @@ defmodule Kernel.Typespec do
855
865
856
866
defp typespec ( { :fun , meta , args } , vars , caller , state ) do
857
867
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
858
- { { :type , line ( meta ) , :fun , args } , state }
868
+ { { :type , location ( meta ) , :fun , args } , state }
859
869
end
860
870
861
871
defp typespec ( { :... , _meta , _args } , _vars , caller , _state ) do
@@ -872,7 +882,7 @@ defmodule Kernel.Typespec do
872
882
873
883
case :erl_internal . is_type ( name , arity ) do
874
884
true ->
875
- { { :type , line ( meta ) , name , args } , state }
885
+ { { :type , location ( meta ) , name , args } , state }
876
886
877
887
false ->
878
888
if state . undefined_type_error_enabled? and
@@ -890,7 +900,7 @@ defmodule Kernel.Typespec do
890
900
% { state | used_type_pairs: [ { name , arity } | state . used_type_pairs ] }
891
901
end
892
902
893
- { { :user_type , line ( meta ) , name , args } , state }
903
+ { { :user_type , location ( meta ) , name , args } , state }
894
904
end
895
905
end
896
906
@@ -963,7 +973,7 @@ defmodule Kernel.Typespec do
963
973
964
974
defp remote_type ( { remote , meta , name , args } , vars , caller , state ) do
965
975
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
966
- { { :remote_type , line ( meta ) , [ remote , name , args ] } , state }
976
+ { { :remote_type , location ( meta ) , [ remote , name , args ] } , state }
967
977
end
968
978
969
979
defp collect_union ( { :| , _ , [ a , b ] } ) , do: [ a | collect_union ( b ) ]
@@ -996,16 +1006,16 @@ defmodule Kernel.Typespec do
996
1006
end
997
1007
998
1008
defp fn_args ( meta , [ { :... , _ , _ } ] , _vars , _caller , state ) do
999
- { { :type , line ( meta ) , :any } , state }
1009
+ { { :type , location ( meta ) , :any } , state }
1000
1010
end
1001
1011
1002
1012
defp fn_args ( meta , args , vars , caller , state ) do
1003
1013
{ args , state } = :lists . mapfoldl ( & typespec ( & 1 , vars , caller , & 2 ) , state , args )
1004
- { { :type , line ( meta ) , :product , args } , state }
1014
+ { { :type , location ( meta ) , :product , args } , state }
1005
1015
end
1006
1016
1007
1017
defp variable ( { name , meta , args } ) when is_atom ( name ) and is_atom ( args ) do
1008
- { :var , line ( meta ) , name }
1018
+ { :var , location ( meta ) , name }
1009
1019
end
1010
1020
1011
1021
defp variable ( expr ) , do: expr
0 commit comments