Type is not inferred correctly

Probably this is a bug.

I have this simple excerpt of code:

import java.nio.file._

for (f <- Files.newDirectoryStream(Paths.get("/home"))) {
   ....
     
}


"fich" is detected as "Any" when it should be a "Path".

So, I don't have code completion on "fich".

I use latest IDEA 13 and Scala plugin.  It used to happen also with IDEA 12.
I'm using JDK 7 and Scala 2.10.3.
Thanks in advance for any tip.

0
7 comments
Avatar
Permanently deleted user

The expression on the right side of your `<-` evaluates to a `java.nio.file.DirectoryStream[java.nio.file.Path]`. To put it simple: This is not a Scala collection and cannot be used in a for-comprehension as you intend.

0
Avatar
Permanently deleted user

Thanks for your answer.

I forgot to tell you, I've used

import scala.collection.JavaConversions._

The code compiles and runs ok, only editor type awareness is wrong.
The DirectoryStream is a Java Iterable.
0

Your example works ok for me. Do you have some example sbt project, with this sample code?

Best regards,
Alexander Podkhalyuzin.

0
Avatar
Permanently deleted user

Better than that, I'm providing you a complete and simple scala script:

#!/bin/sh
exec scala -feature -savecompiled "$0" "$@"
!#
import java.nio.file._
import scala.collection.JavaConversions._

for (f <- Files.newDirectoryStream(Paths.get("/tmp"))) {
  println(f.getFileName)
}

IDEA plugin doesn't complain about the missing getFileName method, even though it thinks "f" is an Any object.

0

It's still ok for me with Scala 2.10.3 and JDK 1.7_40.

Best regards,
Alexander Podkhalyuzin.

0
Avatar
Permanently deleted user

That's true, I have another installation of IDEA 13 and it works ok.
The difference, is that I have updated the Scala plugin just today.
When I have access to the other computer I will check.

0
Avatar
Permanently deleted user

Confirmed that latest updates in the plugin have solved this. :)

0

Please sign in to leave a comment.