aboutsummaryrefslogtreecommitdiff
path: root/tests/neg
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2016-09-12 13:01:28 +0200
committerMartin Odersky <odersky@gmail.com>2016-10-02 16:12:28 +0200
commit845b689a4a652fa79a7d0621f5ebe15bbf9225c7 (patch)
treece308233797b8b032b25c8ed29b6663da8742340 /tests/neg
parentb559aff35d6d365284fc1e05a3ca49a17551df29 (diff)
downloaddotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.tar.gz
dotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.tar.bz2
dotty-845b689a4a652fa79a7d0621f5ebe15bbf9225c7.zip
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
Diffstat (limited to 'tests/neg')
-rw-r--r--tests/neg/inlinevals.scala24
1 files changed, 24 insertions, 0 deletions
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")
+
+}