Skip to content

Commit

Permalink
Fix bitstring type recognition by no longer hiding named types from t…
Browse files Browse the repository at this point in the history
…ypespecs.
  • Loading branch information
Qqwy committed Oct 9, 2021
1 parent dc10efc commit 1311402
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lib/type_check/internals/to_typespec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ defmodule TypeCheck.Internals.ToTypespec do
ast
end

{:"::", _, [_name, type_ast]} ->
# Hide inner named types from the typespec.
type_ast
# {:"::", _, [_name, type_ast]} ->
# # Hide inner named types from the typespec.
# type_ast

ast = {:named_type, _, [_name, type_ast]} ->
if {:named_type, 2} in builtin_imports do
Expand Down Expand Up @@ -136,10 +136,6 @@ defmodule TypeCheck.Internals.ToTypespec do
end

# Relax these types that Elixir's builtin typespecs does not accept
binary when is_binary(binary) ->
quote generated: true, location: :keep do
binary()
end
float when is_float(float) ->
quote generated: true, location: :keep do
float()
Expand Down
14 changes: 14 additions & 0 deletions test/type_check/builtin/sized_binary_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ defmodule TypeCheck.Builtin.SizedBitstringTest do
end
end
end

test "Bitstring syntax is expanded correctly" do
defmodule BitstringExample do
use TypeCheck

@type! empty :: <<>>
@type! prefix_sized :: <<_ :: 10>>
@type! unit_sized :: << _ :: _ * 13 >>
@type! both_sized :: << _ :: 11, _ :: _ * 15 >>
end

assert [both_sized: 0, empty: 0, prefix_sized: 0, unit_sized: 0] =
BitstringExample.__type_check__(:types) |> Enum.sort()
end
end

0 comments on commit 1311402

Please sign in to comment.