diff options
Diffstat (limited to 'tests/pos/i1174.scala')
-rw-r--r-- | tests/pos/i1174.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/pos/i1174.scala b/tests/pos/i1174.scala new file mode 100644 index 000000000..5875a38ad --- /dev/null +++ b/tests/pos/i1174.scala @@ -0,0 +1,19 @@ +import scala.reflect.ClassTag +import scala.util._ + +object Main { + class A + + def constructAs[TTT <: A](implicit ev: ClassTag[TTT]): Try[TTT] = Try { + new A() + }.flatMap { + case ev(inst) => + val b: TTT = inst + Success(inst) + case inst: TTT => + Success(inst) + case _ => + val tag = implicitly[ClassTag[TTT]] + Failure(new ClassCastException(s"Failed to construct instance of class ${tag.runtimeClass.getName}")) + } +} |