diff options
author | Paolo G. Giarrusso <p.giarrusso@gmail.com> | 2014-01-31 19:43:08 +0100 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-10-01 21:01:11 +1000 |
commit | 0d8ca1f5fe335565f861ce2c58f7f684f15a4064 (patch) | |
tree | d36ec77b840f24e164dc6e5436431318bae7d1d4 /test/files/pos | |
parent | 7b591540fd46f4e8d6e4f589efe7abe468d69ca4 (diff) | |
download | scala-0d8ca1f5fe335565f861ce2c58f7f684f15a4064.tar.gz scala-0d8ca1f5fe335565f861ce2c58f7f684f15a4064.tar.bz2 scala-0d8ca1f5fe335565f861ce2c58f7f684f15a4064.zip |
SI-8217 allow abstract type members in objects
Previously, abstract type members were allowed in objects only when inherited,
but not when declared directly. This inconsistency was not intended. In dotty,
abstract type members are allowed in values and represent existentials; so upon
discussion, it was decided to fix things to conform to dotty and allow such type
members. Adriaan also asked to keep rejecting abstract type members in methods
even though they would conceivably make sense.
Discussions happened on #3407, scala/scala-dist#127.
This code is improved from #3442, keeps closer to the current logic, and passes tests.
Existing tests that have been converted to `pos` tests show that
this works, and a new test has been added to show that local
aliases (ie term-owned) without a RHS are still rejected.
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/t3240.scala | 8 | ||||
-rw-r--r-- | test/files/pos/t845.scala | 16 |
2 files changed, 24 insertions, 0 deletions
diff --git a/test/files/pos/t3240.scala b/test/files/pos/t3240.scala new file mode 100644 index 0000000000..cf197a406d --- /dev/null +++ b/test/files/pos/t3240.scala @@ -0,0 +1,8 @@ +class A { + val foo = new { + type t + def apply(a: Option[t], defVal: Any) = { + a.getOrElse(defVal).asInstanceOf[t] + } + } +}
\ No newline at end of file diff --git a/test/files/pos/t845.scala b/test/files/pos/t845.scala new file mode 100644 index 0000000000..ddf6a16f32 --- /dev/null +++ b/test/files/pos/t845.scala @@ -0,0 +1,16 @@ +package test; + +object Test extends App { + type Bar; + trait FooImpl; + + trait Bob { + def bar : Bar with FooImpl; + } + def ifn[A,B](a : A)(f : A => B) = + if (a != null) f(a) else null; + + val bob : Bob = null; + val bar = ifn(bob)(_.bar); + assert(bar == null); +} |