Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix macro crash when handling sealed case classes #634

Merged
merged 2 commits into from
Sep 28, 2024

Conversation

nox213
Copy link
Contributor

@nox213 nox213 commented Sep 26, 2024

Fixes #628

Sealed classes can be instantiated directly. Therefore, when generating the typeTag, I included the sealed class itself. This ensures that the macro correctly handles sealed classes without subclasses. To check whether it’s a sealed class and not a trait or abstract class, I used the following condition:

sealedParents.find(_ == tpe.typeSymbol)

Since trait and abstract class cannot be instantiated, I believe this approach works. However, I could also explicitly check that the symbol is not a trait or an abstract class, if needed.

What do you think?

@lihaoyi
Copy link
Member

lihaoyi commented Sep 28, 2024

@nox213 looks great, thanks!

@lihaoyi lihaoyi merged commit 004ed7e into com-lihaoyi:main Sep 28, 2024
8 checks passed
nox213 added a commit to nox213/upickle that referenced this pull request Dec 7, 2024
Fixes com-lihaoyi#628

Sealed classes can be instantiated directly. Therefore, when generating
the typeTag, I included the sealed class itself. This ensures that the
macro correctly handles sealed classes without subclasses. To check
whether it’s a sealed class and not a trait or abstract class, I used
the following condition:
 ```
 sealedParents.find(_ == tpe.typeSymbol)
```
Since `trait` and `abstract class` cannot be instantiated, I believe this approach works. However, I could also explicitly check that the symbol is not a trait or an abstract class, if needed.

What do you think?

remove unused

wip

make scala2 works

Delete some files

Add more tests

more tests

scala3 writer

fix

polish

clean up

Add helper function

scala3 macro

readers

fix bug

test pass

polish

polish

wip

Add Float32 and Float64 to Msg conversions (com-lihaoyi#613)

Small change to include `Float32` and `Float64` conversions in the `Msg`
class. Currently there is no way to extract floats from `Msg` without a
cast at the call site.

Co-authored-by: Li Haoyi <haoyi.sg@gmail.com>

Update .mill-version (com-lihaoyi#627)

Update and rename build.sc to build.mill (com-lihaoyi#640)

fix

remove unused

Use ListBuffer to preserve orders

polish
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Sealed case class causes compiler crash
2 participants