Closed
Description
It appears that the code in the Given parameters guide does not currently compile due to this line:
inline def summon[T]: T = given match {
case t: T => t
}
I'm fairly new to Dotty, so I've tried to make it compile by changing it to:
inline def summon[T](given t:T): T = t match {
case t: T => t
}
Now, I'm actually not sure if this change is correct, but introducing it leads to a crash in the current master branch (tested on d2db509f7
)
minimized code
Apologies for not being able to minimize this further.
import scala.deriving._
import scala.compiletime.erasedValue
inline def summon[T](given t:T): T = t match {
case t: T => t
}
inline def summonAll[T <: Tuple]: List[Eq[_]] = inline erasedValue[T] match {
case _: Unit => Nil
case _: (t *: ts) => summon[Eq[t]] :: summonAll[ts]
}
trait Eq[T] {
def eqv(x: T, y: T): Boolean
}
object Eq {
given Eq[Int] {
def eqv(x: Int, y: Int) = x == y
}
def check(elem: Eq[_])(x: Any, y: Any): Boolean =
elem.asInstanceOf[Eq[Any]].eqv(x, y)
def iterator[T](p: T) = p.asInstanceOf[Product].productIterator
def eqSum[T](s: Mirror.SumOf[T], elems: List[Eq[_]]): Eq[T] =
new Eq[T] {
def eqv(x: T, y: T): Boolean = {
val ordx = s.ordinal(x)
(s.ordinal(y) == ordx) && check(elems(ordx))(x, y)
}
}
def eqProduct[T](p: Mirror.ProductOf[T], elems: List[Eq[_]]): Eq[T] =
new Eq[T] {
def eqv(x: T, y: T): Boolean =
iterator(x).zip(iterator(y)).zip(elems.iterator).forall {
case ((x, y), elem) => check(elem)(x, y)
}
}
inline given derived[T](given m: Mirror.Of[T]): Eq[T] = {
val elemInstances = summonAll[m.MirroredElemTypes]
inline m match {
case s: Mirror.SumOf[T] => eqSum(s, elemInstances)
case p: Mirror.ProductOf[T] => eqProduct(p, elemInstances)
}
}
}
enum Opt[+T] derives Eq {
case Sm(t: T)
case Nn
}
Stack trace
-- Error: test.scala:10:36 -----------------------------------------------------
10 | case _: (t *: ts) => summon[Eq[t]] :: summonAll[ts]
| ^
|no implicit argument of type Eq[t] was found for parameter t of method summon.
|I found:
|
| Eq.derived[T](/* missing */implicitly[deriving.Mirror.Of[t]])
|
|But no implicit values were found that match type deriving.Mirror.Of[t].
exception occurred while typechecking test.scala
exception occurred while compiling test.scala
java.lang.Error: internal error: type of inlined type argument T is not fully defined, pos = <265..265> while compiling test.scala
Exception in thread "main" java.lang.Error: internal error: type of inlined type argument T is not fully defined, pos = <265..265>
at dotty.tools.dotc.typer.Inferencing$.fullyDefinedType(Inferencing.scala:44)
at dotty.tools.dotc.typer.Inliner.$init$$$anonfun$3(Inliner.scala:246)
at scala.collection.immutable.List.foreach(List.scala:305)
at dotty.tools.dotc.typer.Inliner.<init>(Inliner.scala:246)
at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:115)
at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$6(Typer.scala:2741)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2839)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3045)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2451)
at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:327)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:795)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:795)
at dotty.tools.dotc.typer.Applications$Application.addTyped$1(Applications.scala:532)
at dotty.tools.dotc.typer.Applications$Application.matchArgs(Applications.scala:601)
at dotty.tools.dotc.typer.Applications$Application.init(Applications.scala:353)
at dotty.tools.dotc.typer.Applications$TypedApply.<init>(Applications.scala:692)
at dotty.tools.dotc.typer.Applications$ApplyToUntyped.<init>(Applications.scala:794)
at dotty.tools.dotc.typer.Applications.simpleApply$1(Applications.scala:867)
at dotty.tools.dotc.typer.Applications.realApply$5$$anonfun$4(Applications.scala:920)
at dotty.tools.dotc.typer.Typer.tryEither(Typer.scala:2248)
at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:931)
at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:966)
at dotty.tools.dotc.typer.Inliner$InlineTyper.typedApply(Inliner.scala:1072)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2060)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2240)
at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1539)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2044)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2115)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2183)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2227)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:758)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:762)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2068)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2240)
at dotty.tools.dotc.typer.Inliner$InlineTyper.typedMatchFinish(Inliner.scala:1109)
at dotty.tools.dotc.typer.Typer.typedMatch(Typer.scala:1109)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2073)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:60)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2065)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:583)
at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:115)
at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$6(Typer.scala:2741)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2839)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3045)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2451)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2240)
at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1539)
at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2044)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2115)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2183)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2227)
at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:758)
at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:762)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2068)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.ReTyper.typedTyped(ReTyper.scala:60)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2065)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Inliner.inlined(Inliner.scala:583)
at dotty.tools.dotc.typer.Inliner$.inlineCall(Inliner.scala:115)
at dotty.tools.dotc.typer.Typer.adaptNoArgsOther$6(Typer.scala:2741)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2839)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3045)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2451)
at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:2461)
at dotty.tools.dotc.typer.Typer.readaptSimplified$1(Typer.scala:2462)
at dotty.tools.dotc.typer.Typer.addImplicitArgs$4(Typer.scala:2637)
at dotty.tools.dotc.typer.Typer.adaptNoArgsImplicitMethod$2(Typer.scala:2646)
at dotty.tools.dotc.typer.Typer.adaptNoArgs$1(Typer.scala:2817)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3045)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2451)
at dotty.tools.dotc.typer.Typer.readapt$1(Typer.scala:2461)
at dotty.tools.dotc.typer.Typer.adapt1(Typer.scala:3029)
at dotty.tools.dotc.typer.Typer.adapt(Typer.scala:2451)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Deriving$Deriver.typeclassInstance$1$$anonfun$1$$anonfun$1(Deriving.scala:291)
at dotty.tools.dotc.ast.tpd$.polyDefDef(tpd.scala:262)
at dotty.tools.dotc.typer.Deriving$Deriver.syntheticDef$1(Deriving.scala:295)
at dotty.tools.dotc.typer.Deriving$Deriver.syntheticDefs$$anonfun$1(Deriving.scala:297)
at scala.collection.StrictOptimizedIterableOps.map(StrictOptimizedIterableOps.scala:100)
at scala.collection.StrictOptimizedIterableOps.map$(StrictOptimizedIterableOps.scala:87)
at scala.collection.mutable.ListBuffer.map(ListBuffer.scala:38)
at dotty.tools.dotc.typer.Deriving$Deriver.syntheticDefs(Deriving.scala:297)
at dotty.tools.dotc.typer.Deriving$Deriver.finalize(Deriving.scala:302)
at dotty.tools.dotc.typer.Typer.finalize$2(Typer.scala:2221)
at dotty.tools.dotc.typer.Typer.$anonfun$43(Typer.scala:2227)
at scala.collection.immutable.List.mapConserve(List.scala:444)
at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2227)
at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1852)
at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2091)
at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2152)
at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2164)
at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2240)
at dotty.tools.dotc.typer.FrontEnd.typeCheck$$anonfun$1(FrontEnd.scala:75)
at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.typer.FrontEnd.monitor(FrontEnd.scala:41)
at dotty.tools.dotc.typer.FrontEnd.typeCheck(FrontEnd.scala:79)
at dotty.tools.dotc.typer.FrontEnd.runOn$$anonfun$3(FrontEnd.scala:109)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.immutable.List.foreach(List.scala:305)
at dotty.tools.dotc.typer.FrontEnd.runOn(FrontEnd.scala:109)
at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:159)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
at dotty.tools.dotc.Run.runPhases$5(Run.scala:169)
at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:177)
at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
at dotty.tools.dotc.Run.compileUnits(Run.scala:184)
at dotty.tools.dotc.Run.compileSources(Run.scala:121)
at dotty.tools.dotc.Run.compile(Run.scala:104)
at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
at dotty.tools.dotc.Driver.process(Driver.scala:178)
at dotty.tools.dotc.Driver.process(Driver.scala:147)
at dotty.tools.dotc.Driver.process(Driver.scala:159)
at dotty.tools.dotc.Driver.main(Driver.scala:186)
at dotty.tools.dotc.Main.main(Main.scala)
</details>