(new Iterator[List[Int]] {
def hasNext: Boolean = ???
def next(): List[Int] = ???
}).flatten
gives error:
value flatten is not a member of Iterator[List[Int]]
[error] possible cause: maybe a semicolon is missing before `value flatten'?
[error] }.flatten
[error] ^
[error] one error found
But
(new Iterator[List[Int]] {
def hasNext: Boolean = ???
def next(): List[Int] = ???
}: Iterator[List[Int]]).flatten
works. Also storing the iterator in a val works.
Scala version: 2.11.8
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
Here is a minimal reproduction
Therefore since in 2.11 and 2.12
flatten
onIterator
was provided as an extension method via flattenTraversableOnce the issue would manifest for anonymousIterator
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 viathen it seems to work. The issue seems to be fixed since 2.13.0-M3 where typer phase gives
whilst in 2.13.0 release
flatten
no longer seem to be provided via extension methodThe above expansion seems to be explained by SLS 6.4 Designators