typed_struct
typed_struct copied to clipboard
Seems broken on Elixir 1.14.0
When running the tests on Elixir 1.14.0 / OTP 24, I can see a lot of failures. After my first investigations it seems that neither the @type
nor the @enforce_keys
seem to be generated. The struct itself is generated though.
It seems to be due to a bug in Elixir. Let’s try on Elixir 1.14.1 when it is out.
I checked with Elixir 1.14.0, and it seems like the struct and the type is properly generated, but the tests do fail.
So I checked on v0.3.0 (via asdf instead of nix):
elixir 1.14.3-otp-25
erlang 25.1.2
mix test
gives:
==> typed_struct
Compiling 2 files (.ex)
Generated typed_struct app
..
1) test generates an opaque type if `opaque: true` is set (TypedStructTest)
test/typed_struct_test.exs:133
** (FunctionClauseError) no function clause matching in TypedStructTest.standardise/2
The following arguments were given to TypedStructTest.standardise/2:
# 1
nil
# 2
TypedStructTest.OpaqueTestStruct
code: |> standardise(TypedStructTest.OpaqueTestStruct)
stacktrace:
test/typed_struct_test.exs:250: TypedStructTest.standardise/2
test/typed_struct_test.exs:149: (test)
.
2) test aliases are properly resolved in types (TypedStructTest)
test/typed_struct_test.exs:207
** (FunctionClauseError) no function clause matching in TypedStructTest.standardise/2
The following arguments were given to TypedStructTest.standardise/2:
# 1
nil
# 2
TypedStructTest.TestStructNoAlias
code: |> standardise(TypedStructTest.TestStructNoAlias)
stacktrace:
test/typed_struct_test.exs:250: TypedStructTest.standardise/2
test/typed_struct_test.exs:224: (test)
..
3) test generates a type for the struct (TypedStructTest)
test/typed_struct_test.exs:107
** (FunctionClauseError) no function clause matching in TypedStructTest.standardise/2
The following arguments were given to TypedStructTest.standardise/2:
# 1
nil
# 2
TypedStructTest.TestStruct
code: type1 = @bytecode |> extract_first_type() |> standardise()
stacktrace:
test/typed_struct_test.exs:250: TypedStructTest.standardise/2
test/typed_struct_test.exs:123: (test)
.....................
Finished in 0.2 seconds (0.00s async, 0.2s sync)
29 tests, 3 failures
So it looks like a failure happened and extract_first_type
returns nil if Code.Typespec.fetch_types(bytecode)
doesnt return an {:ok, _ }
tuple. Besides that I m not sure what happened...
This is fixed in my PRs #39 and #40.
See this fork, which is compatible with OTP-26 and Elixir 1.15.