@@ -1419,7 +1419,9 @@ defmodule Code.Formatter do
14191419
14201420 defp bitstring_segment_to_algebra ( { { :"::" , _ , [ segment , spec ] } , i } , state , last ) do
14211421 { doc , state } = quoted_to_algebra ( segment , :parens_arg , state )
1422- { spec , state } = bitstring_spec_to_algebra ( spec , state , state . normalize_bitstring_modifiers )
1422+
1423+ { spec , state } =
1424+ bitstring_spec_to_algebra ( spec , state , state . normalize_bitstring_modifiers , :"::" )
14231425
14241426 spec = wrap_in_parens_if_inspected_atom ( spec )
14251427 spec = if i == last , do: bitstring_wrap_parens ( spec , i , last ) , else: spec
@@ -1438,15 +1440,17 @@ defmodule Code.Formatter do
14381440 { bitstring_wrap_parens ( doc , i , last ) , state }
14391441 end
14401442
1441- defp bitstring_spec_to_algebra ( { op , _ , [ left , right ] } , state , normalize_modifiers )
1443+ defp bitstring_spec_to_algebra ( { op , _ , [ left , right ] } , state , normalize_modifiers , paren_op )
14421444 when op in [ :- , :* ] do
14431445 normalize_modifiers = normalize_modifiers && op != :*
1444- { left , state } = bitstring_spec_to_algebra ( left , state , normalize_modifiers )
1446+ { left , state } = bitstring_spec_to_algebra ( left , state , normalize_modifiers , op )
14451447 { right , state } = bitstring_spec_element_to_algebra ( right , state , normalize_modifiers )
1446- { concat ( concat ( left , Atom . to_string ( op ) ) , right ) , state }
1448+ doc = concat ( concat ( left , Atom . to_string ( op ) ) , right )
1449+ doc = if paren_op == :* , do: wrap_in_parens ( doc ) , else: doc
1450+ { doc , state }
14471451 end
14481452
1449- defp bitstring_spec_to_algebra ( spec , state , normalize_modifiers ) do
1453+ defp bitstring_spec_to_algebra ( spec , state , normalize_modifiers , _paren_op ) do
14501454 bitstring_spec_element_to_algebra ( spec , state , normalize_modifiers )
14511455 end
14521456
0 commit comments