-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #9751: Fix Inline purity checks #9753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3629,8 +3629,12 @@ class Typer extends Namer | |
} | ||
|
||
private def checkStatementPurity(tree: tpd.Tree)(original: untpd.Tree, exprOwner: Symbol)(using Context): Unit = | ||
if (!tree.tpe.isErroneous && !ctx.isAfterTyper && isPureExpr(tree) && | ||
!tree.tpe.isRef(defn.UnitClass) && !isSelfOrSuperConstrCall(tree)) | ||
if !tree.tpe.isErroneous | ||
&& !ctx.isAfterTyper | ||
&& !tree.isInstanceOf[Inlined] | ||
&& isPureExpr(tree) | ||
&& !isSelfOrSuperConstrCall(tree) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Inlined trees can be pure which is correctly identified in isPureExpr. Here we special case a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the explanation. It might be good to add a short comment after the line. |
||
then | ||
report.warning(PureExpressionInStatementPosition(original, exprOwner), original.srcPos) | ||
|
||
/** Types the body Scala 2 macro declaration `def f = macro <body>` */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
def f(): Unit = { | ||
() // error | ||
() | ||
} | ||
|
||
inline def g(): Unit = { | ||
() // error | ||
() | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
object Test { | ||
extension (x: Int) | ||
inline def times(inline op: Unit): Unit = { | ||
var count = 0 | ||
while count < x do | ||
op | ||
count += 1 | ||
} | ||
|
||
10.times { println("hello") } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
object Test { | ||
inline def f(inline x: Boolean): Unit = | ||
inline if x then println() | ||
|
||
f(true) | ||
f(false) | ||
|
||
inline def g(inline x: => Boolean): Unit = | ||
inline if x then println() | ||
|
||
g(true) | ||
g(false) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it matter? If I were correct, the body of inlined methods is never executed, thus only the TASTY matters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory that seems to be the case. But I caught one that came for the
DottyPredef.assert
when compiling dotty itself. It might be a re-bootstrapping issue.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see. It could be some invariants after the typer -- and it's always good to do so.