Created
February 7, 2012 16:50
-
-
Save hubertp/1760697 to your computer and use it in GitHub Desktop.
Inliner bug
This file contains hidden or 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
trait Types { | |
trait Sth | |
case class A(a: Int) extends Sth { | |
println("New instance of A!" + a) | |
} | |
object Settings { | |
var debug: Boolean = true | |
@inline | |
def report(a: => Sth) = { | |
if (debug) | |
println("Report " + a) | |
} | |
@inline | |
def report2(ref: => A, a: => Sth) = { | |
if (debug) | |
println("Report " + a + " with ref to " + ref) | |
} | |
} | |
@inline | |
final def foo[T](x: => A, y: => Int => A)(f: => T): T = { | |
if (Settings.debug) { | |
val z = x | |
Settings.report(z) | |
val res = f | |
Settings.report2(z, y(z.a)) | |
res | |
} else | |
f | |
} | |
def doNothing(n: Sth): Boolean = true | |
def test1(testVal: Int, n: Sth) { | |
val res = foo(A(10), A(_)) { | |
println("Execute some code") | |
0 | |
} | |
println("RESULT: " + res) | |
} | |
def test2(testVal: Int, n: Sth) { | |
println("TEST 2--------") | |
Settings.debug = false | |
val res = foo(A(10), A(_)) { | |
println("Execute some code") | |
0 | |
} | |
println("RESULT: " + res) | |
} | |
} | |
object InlinerTest { | |
def main(args: Array[String]) { | |
val a = new Types{} | |
a.test1(0, null) | |
a.test2(0, null) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment