question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Compile error on Option[String]

See original GitHub issue

Adding 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:closed
  • Created 10 years ago
  • Comments:8 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
stewSquaredcommented, Jun 4, 2015

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:

p(rd.getOrElse(""): String)
p(rd.getOrElse[String](""))

It’s slightly more verbose, but I think we’re all used to occasionally having to add explicit types in scala.

0reactions
lihaoyicommented, Feb 4, 2017

Probably not gonna go away any time soon so let’s close this

Read more comments on GitHub >

github_iconTop Results From Across the Web

Compile error on Option[String] · Issue #16 - GitHub
BasicTests causes a compile-time error that just seems wrong: "OptionString" - { val rd:Option[String] = Some("rd") val s = rd.
Read more >
Passing String::as_str to Option<String>::map() fails to compile ...
I would expect an error about borrowing some moved data. What is this error trying to say? This does compile: let hello =...
Read more >
error while compling - Syntax - Scala Users
[info] Compiling 314 Scala sources and 3 Java sources to ... [error] found : (String, String, Option[String], Option[String], Boolean, ...
Read more >
[Slick 2.0] map to Option[String] in a case class cause compiling error
In the Slick 2.0 document, it says "Nullable columns are represented by Option[T] where T is one of the supported primitive types.
Read more >
"Option String On" Error - Help - UiPath Community Forum
Hey guys, I am facing an issue at UI Path Level 3 Developer, Exercise 1, walkthrough page 11. Compiler error(s) encountered processing ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found