-
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.
The motivation is to use the new fine-grained lock scoping that local lazies have since #5294. Fixes scala/scala-dev#235 Co-Authored-By: Jason Zaugg <jzaugg@gmail.com>
- Loading branch information
Showing
5 changed files
with
86 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
class C { | ||
var ORef: Object = null | ||
def test = { | ||
object O { | ||
assert(!Thread.holdsLock(C.this)) | ||
assert(Thread.holdsLock(ORef)) | ||
} | ||
val captor = new { def oh = O } | ||
val refField = captor.getClass.getDeclaredFields.last | ||
refField.setAccessible(true) | ||
assert(refField.getType.toString.contains("LazyRef"), refField) | ||
ORef = refField.get(captor) | ||
O | ||
} | ||
} | ||
|
||
class D { | ||
var ORef: Object = null | ||
def test = { | ||
lazy val O = { | ||
assert(!Thread.holdsLock(D.this)) | ||
assert(Thread.holdsLock(ORef)) | ||
"O" | ||
} | ||
val captor = new { def oh = O } | ||
val refField = captor.getClass.getDeclaredFields.last | ||
refField.setAccessible(true) | ||
assert(refField.getType.toString.contains("LazyRef"), refField) | ||
ORef = refField.get(captor) | ||
O | ||
} | ||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
new C().test | ||
new D().test | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class C { | ||
val z = 2 | ||
def mod = { object x { val y = z } ; x.y } | ||
} | ||
|
||
object Test extends App { | ||
val c = new C | ||
assert(c.mod == c.z, s"${c.mod} != ${c.z}") | ||
} |
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