-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4866: do not lift try with no catch block #4872
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
Conversation
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.
Can you also add a test to i1692.scala
. This prevented an optimisation on lazy vals that should be applicable now:
class LazyNullable {
...
private[this] val e = "E"
lazy val l4 = try e finally () // null out e
}
object Test {
...
def nullableTests() = {
...
assert(lz.l4 == "E")
assertNull("e")
...
}
...
}
* Lifting is needed only for try-catch expressions that are evaluated in a context | ||
* where the stack might not be empty. `finally` does not attempt to continue evaluation | ||
* after an exception, so the fact that values on the stack are 'lost' does not matter | ||
* (copied from https://github.com/scala/scala/pull/922). |
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.
Indentation of the lines above is off by one character
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.
Done
tests/run/t4866.scala
Outdated
@@ -0,0 +1,27 @@ | |||
// Test that try-finally aren't lifted, but try-catch are. |
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.
Rename i4866.scala
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.
Done
tests/run/t4866.scala
Outdated
var lifted = 0 | ||
|
||
for (f <- o.getClass.getDeclaredMethods) { | ||
f.setAccessible(true) |
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.
Why?
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.
Copypasta. Simplified.
tests/run/t4866.scala
Outdated
def numLifted(o: Object): Int = { | ||
var lifted = 0 | ||
|
||
for (f <- o.getClass.getDeclaredMethods) { |
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.
def isLifted(method: Method) = method.getName.startsWith("lifted")
o.getClass.getDeclaredMethods.count(isLifted)
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.
Thanks. Used it.
tests/run/t4866.scala
Outdated
} | ||
|
||
println("Foo #lifted: %d".format(numLifted(new Foo(new Object)))) | ||
println("FooLifted #lifted: %d".format(numLifted(new FooLifted(new Object)))) |
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.
Why format
?
"Foo #lifted: " + numLifted(new Foo(new Object))
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.
Removed format.
tests/run/t4866.scala
Outdated
@@ -0,0 +1,27 @@ | |||
// Test that try-finally aren't lifted, but try-catch are. | |||
|
|||
class Foo(param: => Object) { |
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.
Do we need a by-name parameter? Let's minimise feature interaction in tests:
class Foo {
def foo: Int = try ??? finally ()
}
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.
We don't. Removed it.
tests/run/t4866.scala
Outdated
val field = try param finally () | ||
} | ||
|
||
class FooLifted(param: => Object) { |
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.
Same as above
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.
Done.
Forward port of scala/scala#922
PTAL |
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.
LGTM! Thanks @abeln!
Forward port of scala/scala#922