diff --git a/README.md b/README.md index 4dbd0d50..facf2831 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,10 @@ Details: ### Changelog - master - + - Fixes: + - Wrapping private functions no longer make the function public. (c.f. #64) + - Wrapping macros now works correctly. (also related to #64) + - Using `__MODULE__` inside a struct inside a type now expands correctly. (c.f. #66) - 0.9.0 - - Support for bitstring type syntax: `<<>>`, `<<_ :: size>>`, `<<_ :: _ * unit>>`, `<<_ :: size, _ :: _ * unit>>` (both as types and as generators) - 0.8.2 - diff --git a/lib/type_check/internals/pre_expander.ex b/lib/type_check/internals/pre_expander.ex index f4f4826a..d44e2e5f 100644 --- a/lib/type_check/internals/pre_expander.ex +++ b/lib/type_check/internals/pre_expander.ex @@ -239,7 +239,7 @@ defmodule TypeCheck.Internals.PreExpander do # TODO wrap in struct-checker quote generated: true, location: :keep do TypeCheck.Builtin.fixed_map( - [__struct__: TypeCheck.Builtin.literal(unquote(struct_name))] ++ unquote(field_types) + [__struct__: unquote(rewrite(struct_name, env, options))] ++ unquote(field_types) ) end end diff --git a/lib/type_check/macros.ex b/lib/type_check/macros.ex index 88ed0f55..ddcb74c3 100644 --- a/lib/type_check/macros.ex +++ b/lib/type_check/macros.ex @@ -526,6 +526,18 @@ defmodule TypeCheck.Macros do end end + def define_type(other, kind, caller) do + raise TypeCheck.CompileError, """ + Compilation error encountered while attempting to create a `#{to_string(kind)}` + in `#{to_string(caller.module)}`. + + Cannot parse syntax: + #{Macro.to_string(other)} + + Maybe you forgot to give the type a name? + """ + end + defp append_typedoc(caller, extra_doc) do {_line, old_doc} = Module.get_attribute(caller.module, :typedoc) || {0, ""} newdoc = old_doc <> extra_doc diff --git a/test/type_check/macros_test.exs b/test/type_check/macros_test.exs index df240439..da7f7199 100644 --- a/test/type_check/macros_test.exs +++ b/test/type_check/macros_test.exs @@ -155,4 +155,23 @@ defmodule TypeCheck.MacrosTest do end end) end + + test "__MODULE__ is expanded correctly" do + defmodule ModuleExpansion do + use TypeCheck + + @type! t :: %__MODULE__{name: String.t()} + defstruct [:name] + + @spec! build(String.t()) :: t() + def build(name) do + %__MODULE__{name: name} + end + end + + assert ModuleExpansion.build("hello") == %{__struct__: ModuleExpansion, name: "hello"} + assert_raise TypeCheck.TypeError, fn -> + ModuleExpansion.build(:not_a_string) + end + end end