Skip to content

Conversation

@odersky
Copy link
Contributor

@odersky odersky commented Jan 29, 2020

No description provided.

@odersky odersky requested a review from bishabosha January 29, 2020 15:07
@odersky odersky added this to the 0.22 Tech Preview milestone Jan 30, 2020
@smarter
Copy link
Member

smarter commented Jan 30, 2020

I recently noticed this and I wonder if the same sort of fix could be applied:

object Test {
  def test: Unit = {
    println("1")

      (x: Int) => 0

    println("2")
  }
}

You might think the body of the lambda is just 0, and the warning would agree with you:

-- [E129] Potential Issue Warning: try/indentlambda.scala:5:18 -----------------
5 |      (x: Int) => 0
  |                  ^
  |A pure expression does nothing in statement position; you may be omitting necessary parentheses

but actually every line after that is also part of the body of the lambda:

result of try/indentlambda.scala after typer:
package <empty> {
  final lazy module val Test: Test$ = new Test$()
  final module class Test$() extends Object(), _root_.scala.Serializable {
    this: Test.type =>
    def test: Unit =
      {
        println("1")
        {
          {
            def $anonfun(x: Int): Unit =
              {
                0
                println("2")
              }
            closure($anonfun)
          }
          ()
        }
      }
  }
}

(scalac does the same)

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current run test indeed proves that "OK" is not swallowed by the catch, but perhaps this neg test should be added, which compiles on 0.21:

def k: Unit =
  val s: String = try
    "WUT"
  catch case t => println("caught something") // error: Type Mismatch Error

  "OK" // warning: A pure expression does nothing in statement position

@bishabosha bishabosha merged commit 7724627 into scala:master Jan 30, 2020
@bishabosha bishabosha deleted the fix-#8096 branch January 30, 2020 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants