You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So here's an example with a bunch of GADT issues; they should be diagnosed and minimized.
importscala.collection.generic.CanBuildFromsealedtraitExp[T]
caseclassIntLit(n: Int) extendsExp[Int]
caseclassGenLit[T](t: T) extendsExp[T]
caseclassPlus(e1: Exp[Int], e2: Exp[Int]) extendsExp[Int]
caseclassFun[S, T](f: Exp[S] =>Exp[T]) extendsExp[S=>T]
caseclassApp[T, U](f: Exp[T=>U], e: Exp[T]) extendsExp[U]
caseclassMapS[S, T](xs: Exp[List[S]], f: Exp[S=>T]) extendsExp[List[T]]
caseclassMap[S, T, That](xs: Exp[List[S]], f: Exp[S=>T])(implicitvalcbf:CanBuildFrom[List[S], T, That]) extendsExp[That]
//def map[B, That](f: (A) ⇒ B)(implicit bf: CanBuildFrom[List[A], B, That]): ThatobjectInterpreter {
defeval[T](e: Exp[T]):T= e match {
caseIntLit(n) =>// Here T = Int and n: Int
n
casegl: GenLit[_] =>// Here in fact gl: GenLit[T]// the next line was incorrectly allowed before the fix to https://github.com/lampepfl/dotty/issues/1754://val gl1: GenLit[Nothing] = gl
gl.t
casePlus(e1, e2) =>// Here T = Int and e1, e2: Exp[Int]
eval(e1) + eval(e2)
// The next cases triggered warnings before the fix to// https://github.com/lampepfl/dotty/issues/3666casef: Fun[s, t] =>// Here T = s => t//val f1: Exp[Nothing] => Exp[Nothing] = f.f
(v: s) => eval(f.f(GenLit(v)))
caseApp(f, e) =>// Here f: Exp[s, T] and e: Exp[s]
eval(f)(eval(e))
case m @Map(xs, f) =>//val f1: Exp[Any => Any] = f // spuriously accepted by Scalac, rejected by Dotty.
eval(xs).map(eval(f))(m.cbf)
// case MapS(xs, f) =>// eval(xs) map eval(f) // accepted by Scalac, spuriously (?) rejected by Dottycasem: MapS[s, t] =>//(eval(m.xs) map eval(m.f))(List.canBuildFrom) //fails in Dotty
(eval(m.xs) map eval(m.f))(List.canBuildFrom[t]) //succeeds in Dotty
}
defbetaReduce[T](e: Exp[T]):Exp[T] = e match {
caseApp(Fun(f), arg) => f(arg)
case _ => e
}
}
the body of eval(Fun(...)) must give a type annotation to v, writing (v: s) => eval(f.f(GenLit(v))). Since the typechecker knows the result type is T and that T = s => t, this annotation should not be necessary; @smarter suggested this might be because the GADT bounds are stored separately and the typechecker would have to look at them, which should be doable.
I'd expect to be able to write instead:
caseFun(f) =>
v => eval(f(GenLit(v)))
The text was updated successfully, but these errors were encountered:
Implicit search does not appear to look in GADT bounds. Correct bound is inferred on the side of GADTMap (that T := List[MapS#T]). Making MapS#T an explicit member and explicitly annotating the result of map as List[MapS#T] lets the code compile.
Here's a much smaller example, which does not compile in Dotty either, but is compiled by Scalac:
sealedtraitExpr[T]
objectIntExprextendsExpr[Int]
implicitvali:Int=0deftest[T](e: Expr[T]):T= e match { caseIntExpr=> implicitly }
So here's an example with a bunch of GADT issues; they should be diagnosed and minimized.
eval(xs) map eval(f)
seems to fail because of GADT bounds are not precise enough #4075I wild-guess that
(eval(m.xs) map eval(m.f))(List.canBuildFrom)
might not be able to infert
because it's not "frozen" yet — errors in Add test to close #3666, problems with typechecking GADTs #4069 complain about that.the body of
eval(Fun(...))
must give a type annotation tov
, writing(v: s) => eval(f.f(GenLit(v)))
. Since the typechecker knows the result type isT
and thatT = s => t
, this annotation should not be necessary; @smarter suggested this might be because the GADT bounds are stored separately and the typechecker would have to look at them, which should be doable.I'd expect to be able to write instead:
The text was updated successfully, but these errors were encountered: