diff options
author | Paul Phillips <paulp@improving.org> | 2012-09-27 16:12:50 -0700 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-09-28 14:22:05 +0200 |
commit | b5b614444cefe84861b06a09fbaf10d100556556 (patch) | |
tree | 1b7b0e8f8410daa2cd41b76257d09e97ad4a0958 /test/files/run/fail-non-value-types.scala | |
parent | a6b81ac12a45866e97d30133c12dee775b93ea39 (diff) | |
download | scala-b5b614444cefe84861b06a09fbaf10d100556556.tar.gz scala-b5b614444cefe84861b06a09fbaf10d100556556.tar.bz2 scala-b5b614444cefe84861b06a09fbaf10d100556556.zip |
Implementations of isValueType and isNonValueType.
Restrictions regarding how non-value types can be used have
generally not been enforced explicitly, depending instead on
the fact that the compiler wouldn't attempt to use them in
strange ways like offering a method type as a type argument.
Since users can now create most types from scratch, it has
become important to enforce the restrictions in a more
direct fashion.
This was a lot harder than it probably should have been
because there are so many types which go unmentioned by the
specification. Hopefully a useful exercise in any case.
Diffstat (limited to 'test/files/run/fail-non-value-types.scala')
-rw-r--r-- | test/files/run/fail-non-value-types.scala | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/files/run/fail-non-value-types.scala b/test/files/run/fail-non-value-types.scala new file mode 100644 index 0000000000..d9aa5c01ca --- /dev/null +++ b/test/files/run/fail-non-value-types.scala @@ -0,0 +1,30 @@ +import scala.reflect.runtime.universe._ + +class ImaginaryCanBuildFrom[-From, -Elem, +To] +class CompletelyIndependentList[+A] { + type Repr <: CompletelyIndependentList[A] + def map[B, That](f: A => B)(implicit cbf: ImaginaryCanBuildFrom[Repr, B, That]): That = ??? + def distinct(): CompletelyIndependentList[A] = ??? +} + +object Test { + var failed = false + def expectFailure[T](body: => T): Boolean = { + try { val res = body ; failed = true ; println(res + " failed to fail.") ; false } + catch { case _: AssertionError => true } + } + + /** Attempt to use a method type as a type argument - expect failure. */ + def tcon[T: TypeTag](args: Type*) = appliedType(typeOf[T].typeConstructor, args.toList) + + val map = typeOf[CompletelyIndependentList[Int]].member("map": TermName).typeSignature + val distinct = typeOf[CompletelyIndependentList[Int]].member("distinct": TermName).typeSignature + + def main(args: Array[String]): Unit = { + expectFailure(println(tcon[CompletelyIndependentList[Int]](map))) + expectFailure(tcon[CompletelyIndependentList[Int]](distinct)) + println(map) + println(distinct) + if (failed) sys.exit(1) + } +} |