Skip to content

Instantly share code, notes, and snippets.

********************************************************************************
tpe.typeSymbol: TypeDef(
Foo,
Template(
DefDef(
<init>,
List(
List(
ValDef(
x,
@mrdziuban
mrdziuban / semiauto-sealed-trait-option4.scala
Created November 27, 2023 14:38
semiauto-sealed-trait-option4.scala
sealed trait Test1
object Test1 {
case object Member extends Test1
}
sealed trait Test2
object Test2 {
sealed trait SubTrait extends Test2
case object Member extends SubTrait
}
@mrdziuban
mrdziuban / semiauto-sealed-trait-option3.scala
Created November 27, 2023 14:37
semiauto-sealed-trait-option3.scala
sealed trait Test1
object Test1 {
case object Member extends Test1
}
sealed trait Test2
object Test2 {
sealed trait SubTrait extends Test2
case object Member extends SubTrait
}
@mrdziuban
mrdziuban / semiauto-sealed-trait-option2.scala
Created November 27, 2023 14:35
semiauto-sealed-trait-option2.scala
sealed trait Test1
object Test1 {
case object Member extends Test1
}
sealed trait Test2
object Test2 {
sealed trait SubTrait extends Test2
case object Member extends SubTrait
}
@mrdziuban
mrdziuban / semiauto-sealed-trait-option1.scala
Last active November 27, 2023 14:28
semiauto-sealed-trait-option1.scala
sealed trait Test1
object Test1 {
case object Member extends Test1
}
sealed trait Test2
object Test2 {
sealed trait SubTrait extends Test2
case object Member extends SubTrait
}
@mrdziuban
mrdziuban / semiauto-case-class-option2.scala
Created November 27, 2023 14:14
semiauto-case-class-option2.scala
case class Foo()
case class Bar(foo: Foo)
// succeeds and automatically derives a `Decoder[Foo]`
io.circe.Decoder.derived[Bar]
@mrdziuban
mrdziuban / semiauto-case-class-option1.scala
Created November 27, 2023 14:12
semiauto-case-class-option1.scala
case class Foo()
case class Bar(foo: Foo)
// fails because there is no `Decoder[Foo]`
io.circe.Decoder.derived[Bar]
java.lang.StackOverflowError
at dotty.tools.dotc.core.Types$VariantTraversal.stopBecauseStaticOrLocal(Types.scala:5539)
at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5656)
at dotty.tools.dotc.core.TypeComparer$$anon$1.apply(TypeComparer.scala:266)
at dotty.tools.dotc.core.Types$TypeMap.op$proxy18$1(Types.scala:5658)
at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5658)
at dotty.tools.dotc.core.TypeComparer$$anon$1.apply(TypeComparer.scala:266)
at dotty.tools.dotc.core.Types$TypeMap.op$proxy17$1(Types.scala:5625)
at dotty.tools.dotc.core.Types$TypeMap.mapArgs(Types.scala:5625)
at dotty.tools.dotc.core.Types$TypeMap.mapOver(Types.scala:5662)
@mrdziuban
mrdziuban / autoGiven.scala
Created December 15, 2022 17:12
autoGiven.scala
import scala.annotation.MacroAnnotation
import scala.quoted.*
class autoGiven extends MacroAnnotation {
final def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = {
import quotes.reflect.*
tree match {
case ValDef(name, tpt, Some(rhs)) => rhs.asExpr match {
case '{ $rhsExpr: t } =>
java.lang.StackOverflowError while typechecking /path/to/file.scala
scala.runtime.Statics.anyHash(Statics.java:127)
scala.collection.immutable.HashMap.get(HashMap.scala:136)
dotty.tools.dotc.core.Contexts$Context.property(Contexts.scala:154)
dotty.tools.dotc.printing.PlainPrinter.limiter(PlainPrinter.scala:37)
dotty.tools.dotc.printing.PlainPrinter.controlled(PlainPrinter.scala:39)
dotty.tools.dotc.printing.RefinedPrinter.toText(RefinedPrinter.scala:307)
dotty.tools.dotc.core.Types$Type.toText(Types.scala:1911)
dotty.tools.dotc.printing.Printer.toTextLocal$$anonfun$1(Printer.scala:170)
dotty.tools.dotc.printing.Printer.atPrec(Printer.scala:43)