-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8995 from retronym/topic/pure-expression-defer
- Loading branch information
Showing
17 changed files
with
110 additions
and
107 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
names-defaults-neg-213.scala:7: warning: a pure expression does nothing in statement position | ||
f1(x = 1) // named arg in 2.13 (value discard), not ambiguous | ||
^ | ||
names-defaults-neg-213.scala:8: error: unknown parameter name: x | ||
Note that assignments in argument position are no longer allowed since Scala 2.13. | ||
To express the assignment expression, wrap it in brackets, e.g., `{ x = ... }`. | ||
f2(x = 1) // error, no parameter named x. error message mentions change in 2.13 | ||
^ | ||
names-defaults-neg-213.scala:13: warning: a pure expression does nothing in statement position | ||
f1(x = 1) // ok, named arg (value discard) | ||
^ | ||
names-defaults-neg-213.scala:14: error: unknown parameter name: x | ||
f2(x = 1) // error (no such parameter). no mention of new semantics in 2.13 | ||
^ | ||
two warnings found | ||
two errors found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
contrib674.scala:15: warning: a pure expression does nothing in statement position | ||
contrib674.scala:15: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
1 | ||
^ | ||
contrib674.scala:15: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
contrib674.scala:15: warning: a pure expression does nothing in statement position | ||
1 | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
patmatnew.scala:670: warning: This catches all Throwables. If this is really intended, use `case e : Throwable` to clear this warning. | ||
case e => { | ||
^ | ||
patmatnew.scala:489: warning: unreachable code | ||
case _ if false => | ||
^ | ||
patmatnew.scala:351: warning: a pure expression does nothing in statement position | ||
case 1 => "OK" | ||
^ | ||
patmatnew.scala:352: warning: a pure expression does nothing in statement position | ||
patmatnew.scala:352: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
case 2 => assert(false); "KO" | ||
^ | ||
patmatnew.scala:352: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
patmatnew.scala:352: warning: a pure expression does nothing in statement position | ||
case 2 => assert(false); "KO" | ||
^ | ||
patmatnew.scala:353: warning: a pure expression does nothing in statement position | ||
patmatnew.scala:353: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
case 3 => assert(false); "KO" | ||
^ | ||
patmatnew.scala:353: warning: multiline expressions might require enclosing parentheses; a value can be silently discarded when Unit is expected | ||
patmatnew.scala:353: warning: a pure expression does nothing in statement position | ||
case 3 => assert(false); "KO" | ||
^ | ||
patmatnew.scala:670: warning: This catches all Throwables. If this is really intended, use `case e : Throwable` to clear this warning. | ||
case e => { | ||
^ | ||
patmatnew.scala:489: warning: unreachable code | ||
case _ if false => | ||
^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import scala.language.experimental.macros | ||
import scala.reflect.macros.blackbox.Context | ||
|
||
object Macro { | ||
def blockToList[T](block: T): List[T] = macro impl[T] | ||
def impl[T: c.WeakTypeTag](c: Context)(block: c.Tree): c.Tree = { | ||
import c.universe._ | ||
block match { | ||
case Block(stats, expr) => | ||
q"_root_.scala.List.apply[${weakTypeOf[T]}](..${stats :+ expr})" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// scalac: -Xfatal-errors | ||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
// We don't want a "pure expression discarded" warning here as the macro will | ||
// eliminate the block | ||
val is = Macro.blockToList[Int] { | ||
1 | ||
2 | ||
3 | ||
} | ||
assert(is == List(1, 2, 3)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
reify_lazyunit.scala:6: warning: a pure expression does nothing in statement position; multiline expressions might require enclosing parentheses | ||
lazy val x = { 0; println("12")} | ||
^ | ||
12 | ||
one | ||
two |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.