mathieuprog / polymorphic_embed

Polymorphic embeds in Ecto
Apache License 2.0
340 stars 62 forks source link

Add @type t() to prevent Dialyzer warnings #96

Closed kirillrogovoy closed 6 months ago

kirillrogovoy commented 6 months ago

Hey,

I don't know if this is the best fix for the issue, but I've noticed that Dialyzer emits the following kind of warning for each PolymorphicEmbed usage:

lib/app/incubator/result.ex:0:unknown_type
Unknown type: PolymorphicEmbed.t/0.

You can reproduce it by simply creating a new barebones Elixir/Phoenix project, adding Dialyzer, and then trying to use PolymorphicEmbed according to the README.

Again, though this change completely solves the issue for me, I looks and feels like a hack since PolymorphicEmbed doesn't define any structs to begin with. But I got stuck trying to understand where exactly that .t() is being called inside or outside of Dialyzer. 😬

kirillrogovoy commented 6 months ago

Oops, sorry, found the original issue: https://github.com/bamorim/typed_ecto_schema/issues/40

I missed the fact I was using typed_ecto_schema and, yeah, it assumed that a .t() would exist on a third-party module when generating the typespec.

But still wondering if we should provide the "stub" t() type here at least as a workaround.

mathieuprog commented 6 months ago

As you can see, I don't use typespecs 😬 I do not really understand the implications of adding your suggestion.

kirillrogovoy commented 6 months ago

Yeah, I guess what I was trying to say is that it upsets Dialyzer when using in combination with https://github.com/bamorim/typed_ecto_schema because typed_ecto_schema assumes that there's a typespec for any underlying struct.

It's probably not polymorphic_embed's problem per se, but adding some catch-all spec would hurt nobody, require no maintenance but solve a minor annoyance. :)

Maybe even say that it's a map not any

mathieuprog commented 6 months ago

Could you update from the current master and keep any?

kirillrogovoy commented 6 months ago

Oops, didn't see the rebase.

Done now.

kirillrogovoy commented 6 months ago

Thanks! 🙌

mathieuprog commented 6 months ago

I'll release it soon. Queueing up a few changes. Ty