Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Not a Bug
    • Affects Version/s: Scala 2.10.0-RC2
    • Fix Version/s: Scala 2.10.1
    • Component/s: Reflection
    • Labels:

      Description

      Welcome to Scala version 2.10.0-RC2 (Java HotSpot(TM) Client VM, Java 1.7.0_09).
      
      Type in expressions to have them evaluated.
      Type :help for more information.
      
      scala> import reflect.runtime.universe._
      import reflect.runtime.universe._
      
      scala> Block(Ident("foo"))
      res0: reflect.runtime.universe.Block =
      {
        foo;
        ()
      }
      

      The pair of brackets change the result type to Unit, and I want it just be a foo.

        Activity

        Hide
        Jason Zaugg added a comment - - edited

        Eugene: is this intentional?

        src/reflect/scala/reflect/internal/Trees.scala
          /** Block factory that flattens directly nested blocks.
           */
          def Block(stats: Tree*): Block = {
            if (stats.isEmpty) Block(Nil, Literal(Constant(())))
            else stats match {
              case Seq(b @ Block(_, _)) => b
              case Seq(stat) => Block(stats.toList, Literal(Constant(())))
              case Seq(_, rest @ _*) => Block(stats.init.toList, stats.last)
            }
          }
        
        Show
        Jason Zaugg added a comment - - edited Eugene: is this intentional? src/reflect/scala/reflect/internal/Trees.scala /** Block factory that flattens directly nested blocks. */ def Block(stats: Tree*): Block = { if (stats.isEmpty) Block(Nil, Literal(Constant(()))) else stats match { case Seq(b @ Block(_, _)) => b case Seq(stat) => Block(stats.toList, Literal(Constant(()))) case Seq(_, rest @ _*) => Block(stats.init.toList, stats.last) } }
        Hide
        Eugene Burmako added a comment -

        @杨博: Use Block(Nil, Ident("foo")) instead.

        @Jason: It looks like we need to jettison all the "helper" tree factory methods I exposed from the compiler. Ident("foo") without explicitly specifying newTermName gives me shivers.

        Show
        Eugene Burmako added a comment - @杨博: Use Block(Nil, Ident("foo")) instead. @Jason: It looks like we need to jettison all the "helper" tree factory methods I exposed from the compiler. Ident("foo") without explicitly specifying newTermName gives me shivers.
        Hide
        Eugene Burmako added a comment -

        I'm closing this issue, because it's not a bug per se, just a problem with misleading methods that made it to the public API.

        Show
        Eugene Burmako added a comment - I'm closing this issue, because it's not a bug per se, just a problem with misleading methods that made it to the public API.
        Show
        Eugene Burmako added a comment - https://github.com/scala/scala/pull/1654

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            杨博
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development