compiler errors - Strange behaviour with for loop and range: found :Int required: scala.collection.generic.CanBuildFrom[Nothing,String,?] -
i bizarre because following code compiled long long time without complaint nor comment.
val depth = dbstuff.lookupsomeint(blah, blah) (x: int <- 0 depth) { dostuffwith(x).ornot }
and yet today did not compile on 1 of machines (while still compiling on another)
here error:
[error] /users/someone/somepath/somefile.scala:415: type mismatch; [error] found : int [error] required: scala.collection.generic.canbuildfrom[nothing,string,?] [error] (x: int <- 0 depth) { [error] ^ [error] 1 error found
further food chain did add val:
protected implicit val columnorderbylist = seq.empty[seq[string]]
this change i'm aware of , error occurred after addition.
the fix appears be:
(x: int <- range(0, depth, 1)) { dostuffwith(x).ornot }
it refused other attempts "range" work: e.g. (0 depth)
in brackets etc.
hate out load errors scare crap out of me. happen if 500 compile errors instead of 1? or if "fix" didn't become self-evident? worse yet if root cause wasn't self evident back-out wasn't possible?
i'm sure genius knows happened here , why have no real idea how find out (as in paths follow) figure out on lonesome...
light welcome!
comfirmed: remove protected implicit val columnorderbylist
, original code compiles no problem -- place in , error documented. food chain mean val
in class inherited class has compile error val
in scope.
this 1 of problem happen when many implicit conversions in scope.
scala> 0 3 res0: scala.collection.immutable.range.inclusive = range(0, 1, 2, 3)
is equivalent to
scala> intwrapper(0) 3 res1: scala.collection.immutable.range.inclusive = range(0, 1, 2, 3)
however,
scala> implicit val s: seq[seq[string]] = null s: seq[seq[string]] = null scala> 0 3 <console>:12: error: type mismatch; found : int(3) required: scala.collection.generic.canbuildfrom[nothing,string,?] 0 3 ^
is equivalent
scala> s(0) 3 <console>:12: error: type mismatch; found : int(3) required: scala.collection.generic.canbuildfrom[nothing,string,?] s(0) 3 ^ scala> s.apply(0) 3 <console>:12: error: type mismatch; found : int(3) required: scala.collection.generic.canbuildfrom[nothing,string,?] s.apply(0) 3 ^
your newly introduced implicit values has higher preference predefined one, therefore chosen. normally, shouldn't problem, in case seq
defines method to
, can convert collection collection of different type. full signature def to[col[_]](implicit cbf: canbuildfrom[nothing, a, col[a]]): col[a]
, explains error message expected canbuildfrom
.
lection: minimize scope of implicits far possible.
Comments
Post a Comment