              {:type, _, :tuple, [
                {:atom, 0, :timestamp}, {:type, 0, :term, []}, {:atom, 0, :foo}
              ]},
-            []}] = types(module)
+            []}] = types(bytecode)
   end
 
   test "@type with undefined record" do
     assert_raise CompileError, ~r"unknown record :this_record_does_not_exist", fn ->
       test_module do
-        @type mytype :: record(:this_record_does_not_exist, [])
+        @type my_type :: record(:this_record_does_not_exist, [])
       end
     end
   end

            [{:type, _, :fun, [{:type, _, :product, [
                     {:type, _, :fun, [{:type, _, :product, []}, {:type, _, :list, [{:type, _, :integer, []}]}]}]},
                     {:type, _, :integer, []}]}]}] =
           specs(module)
  end

  # Conversion to AST

  test "type_to_ast" do
    quoted = [
      (quote do: @type with_ann() :: (t :: atom())),
      (quote do: @type a_tuple() :: tuple()),
      (quote do: @type empty_tuple() :: {}),
      (quote do: @type one_tuple() :: {:foo}),
      (quote do: @type two_tuple() :: {:foo, :bar}),
      (quote do: @type imm_type_1() :: 1),
      (quote do: @type imm_type_2() :: :foo),
      (quote do: @type simple_type() :: integer()),
      (quote do: @type param_type(p) :: [p]),
      (quote do: @type union_type() :: integer() | binary() | boolean()),
      (quote do: @type binary_type1() :: <<_::_*8>>),
      (quote do: @type binary_type2() :: <<_::3>>),
      (quote do: @type binary_type3() :: <<_::3, _::_*8>>),
      (quote do: @type tuple_type() :: {integer()}),
      (quote do: @type ftype() :: (() -> any()) | (() -> integer()) | ((integer() -> integer()))),
      (quote do: @type cl() :: charlist()),
      (quote do: @type st() :: struct()),
      (quote do: @type ab() :: as_boolean(term())),
      (quote do: @type kw() :: keyword()),
      (quote do: @type kwt() :: keyword(term())),
      (quote do: @type vaf() :: (... -> any())),
      (quote do: @type rng() :: 1..10),
      (quote do: @type opts() :: [first: integer(), step: integer(), last: integer()]),
      (quote do: @type ops() :: {+1, -1}),
      (quote do: @type a_map() :: map()),
      (quote do: @type empty_map() :: %{}),
      (quote do: @type my_map() :: %{hello: :world}),
      (quote do: @type my_req_map() :: %{required(0) => :foo}),
      (quote do: @type my_opt_map() :: %{optional(0) => :foo}),
      (quote do: @type my_struct() :: %Kernel.TypespecTest{hello: :world}),
      (quote do: @type list1() :: list()),
      (quote do: @type list2() :: [0]),
      (quote do: @type list3() :: [...]),
      (quote do: @type list4() :: [0, ...]),
      (quote do: @type nil_list() :: []),
    ] |> Enum.sort

    module = test_module do
      Module.eval_quoted __MODULE__, quoted
    end

    types = types(module)

    Enum.each(Enum.zip(types, quoted), fn {{:type, type}, definition} ->
      ast = Kernel.Typespec.type_to_ast(type)
      assert Macro.to_string(quote do: @type unquote(ast)) == Macro.to_string(definition)
    end)
  end


      test_module do
        require Record
        Record.defrecord :timestamp, [date: 1, time: 2]
        @type my_type :: record(:timestamp, no_field: :foo)
      end
    end
  end
