Uploaded image for project: 'Scala Programming Language'
  1. Scala Programming Language
  2. SI-9027

Semicolon is not inferred after a XML node sequence literal

    Details

      Description

      scalac reports error in the following code;

      object Obj {
        val s1 = <a/><b/>
        println("hi")
      }
       
      value println is not a member of scala.xml.NodeBuffer possible cause: maybe a semicolon is missing before `value println'?
      

      When <a/></b> is either replaced with <a/> alone or enclosed in parentheses or curly braces, code is compiled without error. Entering the semicolon as suggested also allows compilation to proceed.

        Attachments

          Activity

          Hide
          retronym Jason Zaugg added a comment -

          This is intentional (if not ideal), as XML syntax allows newlines within NodeSeq literals.

          :paste
          // Entering paste mode (ctrl-D to finish)
           
          <a/>
          <b/>
          <c/>
           
           
          // Exiting paste mode, now interpreting.
           
          res0: scala.xml.NodeBuffer = ArrayBuffer(<a/>, <b/>, <c/>)
          

          Show
          retronym Jason Zaugg added a comment - This is intentional (if not ideal), as XML syntax allows newlines within NodeSeq literals. :paste // Entering paste mode (ctrl-D to finish)   <a/> <b/> <c/>     // Exiting paste mode, now interpreting.   res0: scala.xml.NodeBuffer = ArrayBuffer(<a/>, <b/>, <c/>)
          Hide
          apm A. P. Marki added a comment -

          But it should not consume whitespace if it looks ahead and detects the end of XML mode.

          https://github.com/scala/scala/pull/4185

          Show
          apm A. P. Marki added a comment - But it should not consume whitespace if it looks ahead and detects the end of XML mode. https://github.com/scala/scala/pull/4185
          Hide
          apm A. P. Marki added a comment -

          This issue sounded very familiar FSR. Why did I use the same example?

          scala> :pa
          // Entering paste mode (ctrl-D to finish)
           
          object X {
            val s = <a/>
                    <b/>
                    <c/>
           
            println("ack")
          }
           
          // Exiting paste mode, now interpreting.
           
          defined object X
           
          scala> X
          ack
          res0: X.type = X$@17f62e33
           
          scala> object X {
               |   val s = <a/><b/>                                           <- spaces are harmless?
               |   println("ack")
               | }
          defined object X
           
          scala> X
          ack
          res1: X.type = X$@3da05287
          

          Show
          apm A. P. Marki added a comment - This issue sounded very familiar FSR. Why did I use the same example? scala> :pa // Entering paste mode (ctrl-D to finish)   object X { val s = <a/> <b/> <c/>   println("ack") }   // Exiting paste mode, now interpreting.   defined object X   scala> X ack res0: X.type = X$@17f62e33   scala> object X { | val s = <a/><b/> <- spaces are harmless? | println("ack") | } defined object X   scala> X ack res1: X.type = X$@3da05287
          Hide
          apm A. P. Marki added a comment -

          Happy to close again if I broke something.

          Show
          apm A. P. Marki added a comment - Happy to close again if I broke something.
          Hide
          ajozwik Andrzej Jozwik added a comment - - edited

          The sbt from version 0.13.7 uses scala compiler to parse the whole file. The problem is, that if you split the file statement by statement and send to the compiler - all will be OK. If you send whole file - you will receive the compilation error.
          See:
          https://github.com/sbt/sbt/issues/1606

          The test from repl:

          scala> :pa
          // Entering paste mode (ctrl-D to finish)
           
          object A {
           
          val a = <a/>
           
          val b = <c/><d/>
          }
           
          // Exiting paste mode, now interpreting.
           
          defined object A
          

          And:

          scala> :pa
          // Entering paste mode (ctrl-D to finish)
           
          object A {
           
          val a = <a/><c/>
           
          val b = <b/>
          }
           
          // Exiting paste mode, now interpreting.
           
          <console>:5: error: ';' expected but 'val' found.
          val b = <b/>
          

          Show
          ajozwik Andrzej Jozwik added a comment - - edited The sbt from version 0.13.7 uses scala compiler to parse the whole file. The problem is, that if you split the file statement by statement and send to the compiler - all will be OK. If you send whole file - you will receive the compilation error. See: https://github.com/sbt/sbt/issues/1606 The test from repl: scala> : pa // Entering paste mode (ctrl-D to finish)   object A {   val a = <a/>   val b = <c/><d/> }   // Exiting paste mode, now interpreting.   defined object A And: scala> : pa // Entering paste mode (ctrl-D to finish)   object A {   val a = <a/><c/>   val b = <b/> }   // Exiting paste mode, now interpreting.   <console> : 5 : error : ';' expected but 'val' found. val b = <b/>
          Show
          grek Grzegorz Kossakowski added a comment - Fixed by https://github.com/scala/scala/pull/4185
          Hide
          grek Grzegorz Kossakowski added a comment -
          Show
          grek Grzegorz Kossakowski added a comment - Backported to 2.10.x in: https://github.com/scala/scala/pull/4186

            People

            • Assignee:
              apm A. P. Marki
              Reporter:
              rkrzewski RafaƂ Krzewski
            • Votes:
              1 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: