Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do I need a trailing semicolon to disambiguate this code?

Tags:

scala

If I omit the semicolon, this code doesn't compile.

def checkRadioButton(xml: DslBuilder): String => XmlTree = {
    val inputs = top(xml).\\*(hasLocalNameX("input"));
    { (buttonValue: String) =>
      // code omitted
    }
}

My guess is that, without the semicolon, scalac thinks that the partial function is another argument to the \\* method, instead of the return value. (It isn't actually a partial function, by the way, it's a total function.)

Can I do without the semicolon here? I've never had to use a semicolon at the end of a line before in Scala.

like image 830
Robin Green Avatar asked Nov 19 '25 18:11

Robin Green


1 Answers

I’d write it like this instead:

def checkRadioButton(xml: DslBuilder): String => XmlTree = {
    val inputs = top(xml).\\*(hasLocalNameX("input"));
    (buttonValue: String) => { // <-- changed position of {
      // code omitted
    }
}
like image 94
Jean-Philippe Pellet Avatar answered Nov 21 '25 08:11

Jean-Philippe Pellet