Monday, August 3, 2009

scala imports and implicit conversions

Scala import statements can be tricky I noticed today

Consider following line:
val entries = Menu(Loc("Home", "/", "Home")) :: Nil;

looks fine, and Intellij agrees, but maven scala plugin complains:
[WARNING] D:\projects\maternal\src\main\scala\bootstrap\liftweb\Boot.scala:17: error: type mismatch;
[WARNING]  found   : java.lang.String("/")
[WARNING]  required: net.liftweb.sitemap.Loc.Link
[WARNING]     val entries = Menu(Loc("Home", "/", "Home")) :: Nil;
[WARNING]                                    ^
[WARNING] one error found


as import entries i have
import net.liftweb.http._
import net.liftweb.sitemap._


which should be sufficient one would think.

however, following statement is needed to import the implicit conversions from a string to a Loc.Link object.

import net.liftweb.sitemap.Loc._


IntelliJ marks this import as 'unused', so it was kind of confusing.