Support covariant typeclass families in Scala 2#628
Support covariant typeclass families in Scala 2#628adamw merged 5 commits intosoftwaremill:scala2from
Conversation
| object Magnolia { | ||
| import CompileTimeState._ | ||
|
|
||
| private[Magnolia] type ConstNothing[a] = Nothing |
There was a problem hiding this comment.
A "typeclass" that is a subtype of any typeclass.
| val subtypeObjects = typeclasses.zipWithIndex.map { case ((subType, typeclass), idx) => | ||
| val symbol = subType.typeSymbol | ||
| val (annotationTrees, inheritedAnnotationTrees) = annotationsOf(symbol) | ||
| q"""$arrayVal($startVal + $idx) = $SubtypeObj[$typeConstructor, $genericType, $subType]( |
There was a problem hiding this comment.
Remove "hard" type specifications where possible.
|
|
||
| val paramsValDef = { | ||
| val method = TermName(if (isReadOnly) "readOnlyParams" else "params") | ||
| q"$PartsObj.$method[$typeConstructor, $genericType](..$paramsItems)" |
There was a problem hiding this comment.
When building paramsVal, we simultaneously let the typer calculate the narrowest subtype of the original Typeclass we can fit over the params. We can then use it instead of the original Typeclass.
| /** Helpers to guide `Param`/`Subtype` array types and to provide access to the resulting typeclass. | ||
| */ | ||
| object Parts { | ||
| def params[TcLower[_], T]: PartiallyApplied[Param[*[_], T], TcLower] = new PartiallyApplied[Param[*[_], T], TcLower]() |
There was a problem hiding this comment.
This is the magic that lets the typer choose a narrower typeclass, while still being constrained by the original Typeclass (TcLower here).
There was a problem hiding this comment.
these are great comments - can you maybe put them as comments on code? they help to understand what's going on :)
There was a problem hiding this comment.
Done. I've also done some cleanup.
|
It seems the build fails? |
Not because of anything in the PR:
It seems that the check uses the runners assigned to your repository, and I can't restart it (which makes sense). I see that you've already tried to restart it with the same result. My best guess is that this is caused by ubuntu-20.04 images being discontinued for GitHub Actions. You've changed the images for the |
## Summary - Replace inline `ci` job with reusable `build-scala.yml` workflow (matches scala3 branch) - Update `mima` and `publish` runners from discontinued `ubuntu-20.04` to `ubuntu-22.04` - Add `label` and `auto-merge` jobs for Scala Steward PRs (matches scala3 branch) Fixes the "maximum execution time while awaiting a runner" issue reported in #628. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
|
Ah of course, thanks for pointing that out. I think the build should be updated now |
|
Thanks! :) |
See #627