Ambiguous Implicit values / Diverging implicit expansion
See original GitHub issueuPickle unable to parse through this code:
import upickle.default._
type Env = Map[String,V]
object Simple {
type Var = String
sealed trait Expr //will be evaluated into V
case class ENum(n: Double) extends Expr
case class EVar(name: String) extends Expr
case class EOp(op: String, es: Seq[Expr]) extends Expr
case class EFun(formal: String, body: Expr) extends Expr
case class EApp(fun: Expr, actual: Expr) extends Expr
sealed trait V //cannot be evaluated further
case class VNum(n: Double) extends V
case class VClosure(x: String, body: Expr, t: Map[String, V]) extends V
sealed trait VorE //a wrapped that excepts either Expr or V
case class Vo(v: V) extends VorE
case class Eo(e: Expr) extends VorE
type Stack = List[K]
sealed trait K //Stack items. Exprs and variables are turned into stack items when placed on stack.
case class KArg(e: Expr) extends K
case class KClosure(formal: String, body: Expr, t: Map[String,V]) extends K
case class KOp(op: String, env: Map[String,V], vals: List[V], exprs: Seq[Expr]) extends K
// These lines compile
// def writeState(state: (List[K], Env, VorE)): String = write(state)
// def readState(str: String): (List[K], Env, VorE) = read[(List[K], Env, VorE)](str)
// These lines do not compile
// def writeKClos(trial: KClosure) : String = write(trial)
// def readKClos(str: String): KClosure = read[KClosure](str)
// These lines do not compile.
def write3Tuple(n: (String, Expr, Map[String, V])): String = write[(String, Expr, Map[String, V])](n)
def read3Tuple(str: String): (String, Expr, Map[String, V]) = read[(String, Expr, Map[String, V])](str)
}
With exactly this code, I get this error message:
[info] Compiling 2 Scala sources… [error] Line 37: ambiguous implicit values: [error] both value derive$macro$249 of type => upickle.default.Writer[(String, Simple.Expr, Map[String,Simple.V])] [error] and value derive$macro$266 of type => upickle.default.Writer[Simple.EOp] [error] match expected type upickle.default.Writer[T1] [error] Error occurred in an application involving default arguments. [error] def write3Tuple(n: (String, Expr, Map[String, V])): String = write(String, Expr, Map[String, V]) [error] ^ [error] Line 38: ambiguous implicit values: [error] both value derive$macro$588 of type => upickle.default.Reader[(String, Simple.Expr, Map[String,Simple.V])] [error] and value derive$macro$605 of type => upickle.default.Reader[Simple.EOp] [error] match expected type upickle.default.Reader[T1] [error] def read3Tuple(str: String): (String, Expr, Map[String, V]) = read(String, Expr, Map[String, V]) [error] ^ [error] two errors found error Compilation failed [error] Total time: 8 s, completed Jun 15, 2016 1:44:19 PM
With the def writeKClos
and def readKClos
uncommented and the last two lines commented, I get:
compile [info] Compiling 2 Scala sources… [error]Line 34: diverging implicit expansion for type upickle.default.Writer[T1] [error] starting with macro method macroW in trait LowPriX [error] Error occurred in an application involving default arguments. [error] def writeKClos(trial: KClosure) : String = write(trial) [error] ^ [error]Line 35: diverging implicit expansion for type upickle.default.Reader[T1] [error] starting with macro method macroR in trait LowPriX [error] def readKClos(str: String): KClosure = readKClosure [error] ^ [error] two errors found error Compilation failed [error] Total time: 11 s, completed Jun 15, 2016 1:54:23 PM
When def writeState
and def readState
are not commented and all following lines are commented, the code compiles fine.
I am not sure what diverging implicit expansion means in terms of how my project is laid out. However, everything that is included in the file should compile file. It does not, and I have no idea why.
Notes: This is all done with sbt on a Mac. Nothing in the project is imported, and no other file uses this file. This is not quite what I was using in the project, but this is the simplest example where the behavior shows.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:13 (2 by maintainers)
Yes I found a workaround. I was trying to use uPickle on a
case class
extending atrait
and it gave me the error. Replacing thetrait
by asealed trait
solved the problem.Bug bankruptcy