@@ -368,34 +368,44 @@ defmodule Module.Types.Descr do
368
368
@ doc """
369
369
Optimized version of `not empty?(intersection(fun(), type))`.
370
370
"""
371
+ def fun_type? ( :term ) , do: true
372
+ def fun_type? ( % { dynamic: :term } ) , do: true
371
373
def fun_type? ( % { dynamic: % { bitmap: bitmap } } ) when ( bitmap &&& @ bit_fun ) != 0 , do: true
372
374
def fun_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_fun ) != 0 , do: true
373
375
def fun_type? ( _ ) , do: false
374
376
375
377
@ doc """
376
378
Optimized version of `not empty?(intersection(binary(), type))`.
377
379
"""
380
+ def binary_type? ( :term ) , do: true
381
+ def binary_type? ( % { dynamic: :term } ) , do: true
378
382
def binary_type? ( % { dynamic: % { bitmap: bitmap } } ) when ( bitmap &&& @ bit_binary ) != 0 , do: true
379
383
def binary_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_binary ) != 0 , do: true
380
384
def binary_type? ( _ ) , do: false
381
385
382
386
@ doc """
383
387
Optimized version of `not empty?(intersection(integer(), type))`.
384
388
"""
389
+ def integer_type? ( :term ) , do: true
390
+ def integer_type? ( % { dynamic: :term } ) , do: true
385
391
def integer_type? ( % { dynamic: % { bitmap: bitmap } } ) when ( bitmap &&& @ bit_integer ) != 0 , do: true
386
392
def integer_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_integer ) != 0 , do: true
387
393
def integer_type? ( _ ) , do: false
388
394
389
395
@ doc """
390
396
Optimized version of `not empty?(intersection(float(), type))`.
391
397
"""
398
+ def float_type? ( :term ) , do: true
399
+ def float_type? ( % { dynamic: :term } ) , do: true
392
400
def float_type? ( % { dynamic: % { bitmap: bitmap } } ) when ( bitmap &&& @ bit_float ) != 0 , do: true
393
401
def float_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_float ) != 0 , do: true
394
402
def float_type? ( _ ) , do: false
395
403
396
404
@ doc """
397
405
Optimized version of `not empty?(intersection(integer() or float(), type))`.
398
406
"""
407
+ def number_type? ( :term ) , do: true
408
+ def number_type? ( % { dynamic: :term } ) , do: true
399
409
def number_type? ( % { dynamic: % { bitmap: bitmap } } ) when ( bitmap &&& @ bit_number ) != 0 , do: true
400
410
def number_type? ( % { bitmap: bitmap } ) when ( bitmap &&& @ bit_number ) != 0 , do: true
401
411
def number_type? ( _ ) , do: false
@@ -442,28 +452,18 @@ defmodule Module.Types.Descr do
442
452
# an empty list of atoms. It is simplified to `0` in set operations, and the key
443
453
# is removed from the map.
444
454
445
- @ doc """
446
- Optimized version of `not empty?(intersection(atom(), type))`.
447
- """
448
- def atom_type? ( % { dynamic: % { atom: _ } } ) , do: true
449
- def atom_type? ( % { atom: _ } ) , do: true
450
- def atom_type? ( _ ) , do: false
451
-
452
455
@ doc """
453
456
Optimized version of `not empty?(intersection(atom([atom]), type))`.
454
457
"""
455
- def atom_type? ( :term , _atom ) , do: false
458
+ def atom_type? ( :term , _atom ) , do: true
456
459
457
460
def atom_type? ( % { } = descr , atom ) do
458
- { static_or_dynamic , static } = Map . pop ( descr , :dynamic , descr )
459
-
460
- atom_only? ( static ) and
461
- case static_or_dynamic do
462
- :term -> true
463
- % { atom: { :union , set } } -> :sets . is_element ( atom , set )
464
- % { atom: { :negation , set } } -> not :sets . is_element ( atom , set )
465
- % { } -> false
466
- end
461
+ case Map . get ( descr , :dynamic , descr ) do
462
+ :term -> true
463
+ % { atom: { :union , set } } -> :sets . is_element ( atom , set )
464
+ % { atom: { :negation , set } } -> not :sets . is_element ( atom , set )
465
+ % { } -> false
466
+ end
467
467
end
468
468
469
469
@ doc """
@@ -704,7 +704,7 @@ defmodule Module.Types.Descr do
704
704
case :maps . take ( :dynamic , descr ) do
705
705
:error ->
706
706
if is_map_key ( descr , :map ) and map_only? ( descr ) do
707
- { static_optional? , static_type } = map_fetch_static ( descr , key ) |> pop_optional_static ( )
707
+ { static_optional? , static_type } = map_fetch_static ( descr , key )
708
708
709
709
if static_optional? or empty? ( static_type ) do
710
710
:badkey
@@ -720,10 +720,8 @@ defmodule Module.Types.Descr do
720
720
721
721
{ dynamic , static } ->
722
722
if is_map_key ( dynamic , :map ) and map_only? ( static ) do
723
- { dynamic_optional? , dynamic_type } =
724
- map_fetch_static ( dynamic , key ) |> pop_optional_static ( )
725
-
726
- { static_optional? , static_type } = map_fetch_static ( static , key ) |> pop_optional_static ( )
723
+ { dynamic_optional? , dynamic_type } = map_fetch_static ( dynamic , key )
724
+ { static_optional? , static_type } = map_fetch_static ( static , key )
727
725
728
726
if static_optional? or empty? ( dynamic_type ) do
729
727
:badkey
@@ -740,8 +738,16 @@ defmodule Module.Types.Descr do
740
738
741
739
defp map_fetch_static ( descr , key ) when is_atom ( key ) do
742
740
case descr do
743
- % { map: map } -> Enum . reduce ( map_split_on_key ( map , key ) , none ( ) , & union / 2 )
744
- % { } -> none ( )
741
+ % { map: [ { :open , fields , [ ] } ] } when fields == % { } ->
742
+ { true , term ( ) }
743
+
744
+ % { map: map } ->
745
+ map_split_on_key ( map , key )
746
+ |> Enum . reduce ( none ( ) , & union / 2 )
747
+ |> pop_optional_static ( )
748
+
749
+ % { } ->
750
+ { false , none ( ) }
745
751
end
746
752
end
747
753
0 commit comments