summaryrefslogtreecommitdiff
path: root/test/files/run/reify_properties.scala
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2015-07-02 16:11:50 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2015-07-02 16:21:28 +0200
commitc42428d76652cbf3ffda1204b8f2e7bb5654f119 (patch)
treea6f02d584cf1e032bcb4fe69d9699e5b149e5c68 /test/files/run/reify_properties.scala
parent743b7297566e9a431e361388c85475deecb71c5e (diff)
downloadscala-c42428d76652cbf3ffda1204b8f2e7bb5654f119.tar.gz
scala-c42428d76652cbf3ffda1204b8f2e7bb5654f119.tar.bz2
scala-c42428d76652cbf3ffda1204b8f2e7bb5654f119.zip
Fix superclass for Java interface symbols created in JavaMirrors
According to the spec [1] the superclass of an interface is always Object. Restores the tests that were moved to pending in bf951ec1, fixex part of SI-9374. [1] https://docs.oracle.com/javase/specs/jvms/se8/html/jvms-4.html#jvms-4.1
Diffstat (limited to 'test/files/run/reify_properties.scala')
-rw-r--r--test/files/run/reify_properties.scala57
1 files changed, 57 insertions, 0 deletions
diff --git a/test/files/run/reify_properties.scala b/test/files/run/reify_properties.scala
new file mode 100644
index 0000000000..01a9b12a92
--- /dev/null
+++ b/test/files/run/reify_properties.scala
@@ -0,0 +1,57 @@
+import scala.reflect.runtime.universe._
+import scala.tools.reflect.Eval
+
+object Test extends App {
+ reify {
+ /** A mutable property whose getter and setter may be customized. */
+ case class Property[T](init: T) {
+ private var value: T = init
+
+ /** The getter function, defaults to identity. */
+ private var setter: T => T = identity[T]
+
+ /** The setter function, defaults to identity. */
+ private var getter: T => T = identity[T]
+
+ /** Retrive the value held in this property. */
+ def apply(): T = getter(value)
+
+ /** Update the value held in this property, through the setter. */
+ def update(newValue: T) = value = setter(newValue)
+
+ /** Change the getter. */
+ def get(newGetter: T => T) = { getter = newGetter; this }
+
+ /** Change the setter */
+ def set(newSetter: T => T) = { setter = newSetter; this }
+ }
+
+ class User {
+ // Create a property with custom getter and setter
+ val firstname = Property("")
+ .get { v => v.toUpperCase() }
+ .set { v => "Mr. " + v }
+ val lastname = Property("<noname>")
+
+ /** Scala provides syntactic sugar for calling 'apply'. Simply
+ * adding a list of arguments between parenthesis (in this case,
+ * an empty list) is translated to a call to 'apply' with those
+ * arguments.
+ */
+ override def toString() = firstname() + " " + lastname()
+ }
+
+ val user1 = new User
+
+ // Syntactic sugar for 'update': an assignment is translated to a
+ // call to method 'update'
+ user1.firstname() = "Robert"
+
+ val user2 = new User
+ user2.firstname() = "bob"
+ user2.lastname() = "KUZ"
+
+ println("user1: " + user1)
+ println("user2: " + user2)
+ }.eval
+}