polymorphic_embed icon indicating copy to clipboard operation
polymorphic_embed copied to clipboard

Add @type t() to prevent Dialyzer warnings

Open kirillrogovoy opened this issue 1 year ago • 1 comments

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 avatar May 21 '24 07:05 kirillrogovoy

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.

kirillrogovoy avatar May 21 '24 07:05 kirillrogovoy

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

mathieuprog avatar May 26 '24 12:05 mathieuprog

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

kirillrogovoy avatar May 26 '24 18:05 kirillrogovoy

Could you update from the current master and keep any?

mathieuprog avatar May 27 '24 00:05 mathieuprog

Oops, didn't see the rebase.

Done now.

kirillrogovoy avatar May 27 '24 07:05 kirillrogovoy

Thanks! 🙌

kirillrogovoy avatar May 27 '24 08:05 kirillrogovoy

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

mathieuprog avatar May 27 '24 08:05 mathieuprog