diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-03 11:05:48 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-07 11:40:03 +1000 |
commit | 51745c06f318f859b313c8257a41221837671ac1 (patch) | |
tree | 3e36f237343fabcd6416701e0f304ae8ed0b4b26 /test/files/pos | |
parent | 2d8f919389fa33a554c5fb828bfa040f1b2531e4 (diff) | |
download | scala-51745c06f318f859b313c8257a41221837671ac1.tar.gz scala-51745c06f318f859b313c8257a41221837671ac1.tar.bz2 scala-51745c06f318f859b313c8257a41221837671ac1.zip |
More uniform treatment of package objects
- Introduce `Symbol#packageObject` and `Type#packageObject`
to lookup the member package object of a package class/module,
and use this far and wide.
- Replace the overly complicated (and still buggy) implementation
of `Context#isInPackageObject` with a one liner. The simplifying
insight is that if we select a symbol from a package prefix
that does not own that symbol, it *must* have really been
selected from the package object.
- Change implicit search to use the cache in
`ModuleSymbol#implicitMembers` via `Type#implicitMembers`,
which lets the client code read more naturally.
Fixes a bug with `adapt::insertApply` that Adriaan spotted in a feat
of lateral thinking. This is tested in t8862b.scala. alladin763.scala
adds the test case from the bug originally remedied by `insertApply`
to check we haven't regressed.
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/alladin763.scala | 37 | ||||
-rw-r--r-- | test/files/pos/t8862b.scala | 12 |
2 files changed, 49 insertions, 0 deletions
diff --git a/test/files/pos/alladin763.scala b/test/files/pos/alladin763.scala new file mode 100644 index 0000000000..29c9b25318 --- /dev/null +++ b/test/files/pos/alladin763.scala @@ -0,0 +1,37 @@ +// Test from http://lrytz.github.io/scala-aladdin-bugtracker/displayItem.do%3Fid=763.html +// and expanded with package object variants + + +trait Foo { type T; def apply() : T } +object e extends Foo { type T = Int; def apply() = 42 } + +package p { + trait T[X] { def O : { def apply(): X } } + object `package` extends T[Int] { + def O: { def apply(): Int } = new { def apply(): Int = 42 } + } + + object Test { + val x: Int = O() + } +} + +object Test { + + val f = new Foo { type T = Int; def apply() = 42 } + + def main(args: Array[String]): Unit = { + val g = new Foo { type T = Int; def apply() = 42 } + + (e: Foo)() + val ee: Int = e() + + (f: Foo)() + val ff: Int = f() + + (g: Foo)() + val gg: Int = g() + + val pp: Int = p.O() + } +} diff --git a/test/files/pos/t8862b.scala b/test/files/pos/t8862b.scala new file mode 100644 index 0000000000..8be7fb5fab --- /dev/null +++ b/test/files/pos/t8862b.scala @@ -0,0 +1,12 @@ +package p { + trait T[X] { def O : { def apply(): X } } + object `package` extends T[Int] { + def O: { def apply(): Int } = new { def apply(): Int = 42 } + } + + object Test { + def main(args: Array[String]): Unit = { + val x: Int = O() + } + } +} |