diff options
Diffstat (limited to 'test/files/run/t10261')
-rw-r--r-- | test/files/run/t10261/Companion_1.scala | 4 | ||||
-rw-r--r-- | test/files/run/t10261/Test_2.scala | 14 |
2 files changed, 18 insertions, 0 deletions
diff --git a/test/files/run/t10261/Companion_1.scala b/test/files/run/t10261/Companion_1.scala new file mode 100644 index 0000000000..9b8e2c73b2 --- /dev/null +++ b/test/files/run/t10261/Companion_1.scala @@ -0,0 +1,4 @@ +trait Companion[T] { + def parse(value: String): Option[T] + def apply(value: String): T = parse(value).get +} diff --git a/test/files/run/t10261/Test_2.scala b/test/files/run/t10261/Test_2.scala new file mode 100644 index 0000000000..d7d9fe9a0e --- /dev/null +++ b/test/files/run/t10261/Test_2.scala @@ -0,0 +1,14 @@ +import scala.util.Try + +object C extends Companion[C] { + def parse(v: String) = if (v.nonEmpty) Some(new C(v)) else None +} + +case class C(value: String) + +object Test { + def main(args: Array[String]): Unit = { + assert(Try{C("")}.isFailure, "Empty value should fail to parse") // check that parse is used to validate input + assert(C("a").value == "a", "Unexpected value") + } +} |