Compile error on Option[String]
See original GitHub issueAdding the following to scalatags.BasicTests causes a compile-time error that just seems wrong:
“OptionString” - {
val rd:Option[String] = Some("rd")
val s = rd.getOrElse("")
assert(s.isInstanceOf[String])
val frag = p( rd.getOrElse("") )
assert(frag.toString == """<td>rd</td>""")
}
The error is
test-only scalatags.BasicTests [info] Compiling 1 Scala source to /Users/bwbecker/temp/scalaTags/target/scala-2.10/test-classes… [error] /Users/bwbecker/temp/scalaTags/shared/test/scala/scalatags/BasicTests.scala:134: type mismatch; [error] found : java.io.Serializable [error] required: scalatags.Modifier [error] val frag = p( rd.getOrElse(“”) ) [error] ^ [error] one error found error Compilation failed [error] Total time: 1 s, completed 24-Feb-2014 8:28:08 AM >
Substituting s for rd.getOrElse(“”) compiles just fine.
The tag doesn’t seem to make a difference: it fails on p(…), td(…), and li(…) with the same error.
Issue Analytics
- State:
- Created 10 years ago
- Comments:8 (4 by maintainers)
Top GitHub Comments
I’m a bit late to this thread, but It’s worth mentioning for the sake of documentation that a type annotation is a simpler fix than having a temporary
val s = ...
Either of the following will compile:
It’s slightly more verbose, but I think we’re all used to occasionally having to add explicit types in scala.
Probably not gonna go away any time soon so let’s close this