Skip to content

Commit 5f8f19e

Browse files
committed
Fix #9751: Widen references to catch inline parameters with unit type
1 parent ce48f5a commit 5f8f19e

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,8 +3629,12 @@ class Typer extends Namer
36293629
}
36303630

36313631
private def checkStatementPurity(tree: tpd.Tree)(original: untpd.Tree, exprOwner: Symbol)(using Context): Unit =
3632-
if (!tree.tpe.isErroneous && !ctx.isAfterTyper && isPureExpr(tree) &&
3633-
!tree.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(tree))
3632+
if !tree.tpe.isErroneous
3633+
&& !ctx.isAfterTyper
3634+
&& isPureExpr(tree)
3635+
&& !tree.tpe.widenTermRefExpr.isRef(defn.UnitClass)
3636+
&& !isSelfOrSuperConstrCall(tree)
3637+
then
36343638
report.warning(PureExpressionInStatementPosition(original, exprOwner), original.srcPos)
36353639

36363640
/** Types the body Scala 2 macro declaration `def f = macro <body>` */
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
object Test {
2+
extension (x: Int)
3+
inline def times(inline op: Unit): Unit = {
4+
var count = 0
5+
while count < x do
6+
op
7+
count += 1
8+
}
9+
10+
10.times { println("hello") }
11+
}

0 commit comments

Comments
 (0)