From 845b689a4a652fa79a7d0621f5ebe15bbf9225c7 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 12 Sep 2016 13:01:28 +0200 Subject: Add inline for vals - allow inline as an alternative to final for vals (final is retained for backwards compatibility for now) - allow inline for parameters - check that rhs of inline value has a constant type - check that arguments to inline value parameters have constant type - check that inline members are not deferred - make inline members effectively final --- tests/neg/inlinevals.scala | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 tests/neg/inlinevals.scala (limited to 'tests/neg/inlinevals.scala') diff --git a/tests/neg/inlinevals.scala b/tests/neg/inlinevals.scala new file mode 100644 index 000000000..184aa2168 --- /dev/null +++ b/tests/neg/inlinevals.scala @@ -0,0 +1,24 @@ +object Test { + + def power(x: Double, inline n: Int): Double = ??? + + inline val N = 10 + def X = 20 + + inline inline val twice = 30 // error: repeated modifier + + class C(inline x: Int, private inline val y: Int) { + inline val foo: Int // error: abstract member may not be inline + inline def bar: Int // error: abstract member may not be inline + } + + power(2.0, N) // ok, since it's a by-name parameter + power(2.0, X) // error: argument to inline parameter must be a constant expression + + inline val M = X // error: rhs must be constant expression + + def byname(inline f: => String): Int = ??? // ok + + byname("hello" ++ " world") + +} -- cgit v1.2.3