Skip to content

Comments

summon sealed trait children definitions for Element Encoder/Decoder instead of auto-deriving#51

Merged
valentiay merged 2 commits intovalentiay:masterfrom
mpipalovic:fix-sealed-trait-not-summoning
Nov 16, 2025
Merged

summon sealed trait children definitions for Element Encoder/Decoder instead of auto-deriving#51
valentiay merged 2 commits intovalentiay:masterfrom
mpipalovic:fix-sealed-trait-not-summoning

Conversation

@mpipalovic
Copy link
Contributor

@mpipalovic mpipalovic commented Nov 14, 2025

Fixes #46

Notice that this is fixed solely by removing the LazySummon; as the only actual place to get an instance of LazySummon was from the ElementDerivedInstances. Meaning, alternative way of making this whole thing work (or fixing the issue at hand) would be by just adding the following:

      given [T: ElementEncoder]: LazySummon[ElementEncoder, T] = new:
        def instance = summon[ElementEncoder[T]]

      given [T: ElementDecoder]: LazySummon[ElementDecoder, T] = new:
        def instance = summon[ElementDecoder[T]]

(you can try this with code from master, and adding the new test with and without the code above)

so e.g. whenever there is a ElementEncoder[T], there would also be an LazySummon[ElementDecoder, T].


But since the name of the LazySummon is kind of misleading

  • since it's not really doing any summoning, but instead it's more like LazyDefaultDerived
  • plus, if we add this code above - then it's no longer even Lazy in any way

So, it just becomes a wrapper that's making things more confusing for no reason with no purpose, so I just removed it


I left the current auto derivation logic for Enums. Also, notice that in case there exists an user provided instance for one of enum children - it would be used (since there's no longer this LazySummon indirection)

@mpipalovic mpipalovic force-pushed the fix-sealed-trait-not-summoning branch 2 times, most recently from 829ae8a to 2b09cf1 Compare November 14, 2025 18:14
@mpipalovic mpipalovic force-pushed the fix-sealed-trait-not-summoning branch from 2b09cf1 to 62956d6 Compare November 14, 2025 18:17
Copy link
Owner

@valentiay valentiay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi! Thanks for your contribution, this is an important fix

@valentiay valentiay added this to the 0.29.0 milestone Nov 16, 2025
@valentiay valentiay merged commit f3a7817 into valentiay:master Nov 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Element encoders and decoders for sealed trait children are ignored

2 participants