I believe this issue was addressed by Include the parts of a compound/refinement type in implicit scope. #5867. The problem was companion to anonymous classes used to not qualify for implicit search
I think aaf9198#diff-7c03397456d3b987549fd039d6b639c6R516 was the
first to exclude refinement/anon classes from contributing to
companion implicits. @odersky Can you remember the motivation?
Here is a minimal reproduction
trait A {
def foo(): Int
}
class B {
def bar(): String = "woohoo"
}
object A {
implicit def aToB(a: A): B = new B
}
(new A {
override def foo(): Int = 42
}).bar()
// Error:
// value bar is not a member of A$A12.this.A
// possible cause: maybe a semicolon is missing before `value bar'? }).bar();
Therefore since in 2.11 and 2.12 flatten
on Iterator
was provided as an extension method via flattenTraversableOnce the issue would manifest for anonymous Iterator
class.
The following is my answer prior to the edit above:
It seems to have something to do with implicit resolution in both 2.11 and 2.12. If you explicitly import flatten
as an extension method via
import scala.collection.TraversableOnce.flattenTraversableOnce
then it seems to work. The issue seems to be fixed since 2.13.0-M3 where typer phase gives
collection.this.TraversableOnce.flattenTraversableOnce[Int, List]({
final class $anon extends AnyRef with Iterator[List[Int]] {
def <init>(): <$anon: Iterator[List[Int]]> = {
$anon.super.<init>();
()
};
def hasNext: Boolean = scala.Predef.???;
def next(): List[Int] = scala.Predef.???
};
new $anon()
})(scala.Predef.$conforms[List[Int]]).flatten
whilst in 2.13.0 release flatten
no longer seem to be provided via extension method
{
final class $anon extends AnyRef with Iterator[List[Int]] {
def <init>(): <$anon: Iterator[List[Int]]> = {
$anon.super.<init>();
()
};
def hasNext: Boolean = scala.Predef.???;
def next(): List[Int] = scala.Predef.???
};
new $anon()
}.flatten[Int](scala.Predef.$conforms[List[Int]])
The above expansion seems to be explained by SLS 6.4 Designators
. is typed as if it was { val = ; . }