8000 Improve unit ascription escape hatch · scala/scala@414ab05 · GitHub
[go: up one dir, main page]

Skip to content

Commit 414ab05

Browse files
committed
Improve unit ascription escape hatch
1 parent 6d0b134 commit 414ab05

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

src/reflect/scala/reflect/internal/TreeInfo.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -788,6 +788,7 @@ abstract class TreeInfo {
788788
case Apply(f, _) => hasExplicitUnit(f)
789789
case TypeApply(f, _) => hasExplicitUnit(f)
790790
case AppliedTypeTree(f, _) => hasExplicitUnit(f)
791+
case Block(_, expr) => hasExplicitUnit(expr)
791792
case _ => false
792793
}
793794
}

test/files/neg/value-discard.scala

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,38 @@ final class UnusedTest {
2525

2626
def u: Unit = f: Unit // nowarn
2727
}
28+
29+
class UnitAscription {
30+
import scala.concurrent._, ExecutionContext.Implicits._
31+
32+
case class C(c: Int) {
33+
def f(i: Int, j: Int = c) = i + j
34+
}
35+
36+
def f(i: Int, j: Int = 27) = i + j
37+
38+
def g[A]: List[A] = Nil
39+
40+
def i: Int = 42
41+
42+
def `default arg is inline`: Unit =
43+
f(i = 42): Unit // nowarn
44+
45+
def `default arg requires block`: Unit =
46+
C(27).f(i = 42): Unit // nowarn
47+
48+
def `application requires implicit arg`: Unit =
49+
Future(42): Unit // nowarn
50+
51+
def `application requires inferred type arg`: Unit =
52+
g: Unit // nowarn
53+
54+
def `implicit selection from this`: Unit =
55+
i: Unit // nowarn
56+
}
57+
58+
object UnitAscription {
59+
def g[A]: List[A] = Nil
60+
def `application requires inferred type arg`: Unit =
61+
g: Unit // nowarn UnitAscription.g
62+
}

0 commit comments

Comments
 (0)
0