aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-12-14 16:13:59 +0100
committerGitHub <noreply@github.com>2016-12-14 16:13:59 +0100
commit19bc03c840f0d6f0678775625562cea5ad7193e7 (patch)
tree0cfa09153cec3fa7b639e6cd6d35d53cbad1bdff
parent7775aab98ce98151d198e88bb676158f58f0cf57 (diff)
parent31337d5223eb9c1824ca72ca399e22c1f2dfe990 (diff)
downloaddotty-19bc03c840f0d6f0678775625562cea5ad7193e7.tar.gz
dotty-19bc03c840f0d6f0678775625562cea5ad7193e7.tar.bz2
dotty-19bc03c840f0d6f0678775625562cea5ad7193e7.zip
Merge pull request #1787 from dotty-staging/fix-i1786
Try fix #1786: support use package object as value
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Checking.scala2
-rw-r--r--tests/neg/i1786.scala17
-rw-r--r--tests/pos/i1786.scala18
3 files changed, 36 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala
index 0c5a8e5db..d80dfe7c0 100644
--- a/compiler/src/dotty/tools/dotc/typer/Checking.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala
@@ -418,7 +418,7 @@ trait Checking {
/** Check that Java statics and packages can only be used in selections.
*/
def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = {
- if (!proto.isInstanceOf[SelectionProto]) {
+ if (!proto.isInstanceOf[SelectionProto] && !proto.isInstanceOf[ApplyingProto]) {
val sym = tree.tpe.termSymbol
// The check is avoided inside Java compilation units because it always fails
// on the singleton type Module.type.
diff --git a/tests/neg/i1786.scala b/tests/neg/i1786.scala
new file mode 100644
index 000000000..7bf513ed8
--- /dev/null
+++ b/tests/neg/i1786.scala
@@ -0,0 +1,17 @@
+package scala
+
+package object meta {
+ def apply(x: Int): Int = x * x
+}
+
+class Test {
+ def f(a: Any): Any = f(meta) // error
+ def g(a: Any): Any = f(scala.meta) // error
+
+ meta { 5 + 4 }
+
+ scala.meta { 3 }
+
+ val m1 = meta // error
+ val m2 = scala.meta // error
+}
diff --git a/tests/pos/i1786.scala b/tests/pos/i1786.scala
new file mode 100644
index 000000000..3b1d3af52
--- /dev/null
+++ b/tests/pos/i1786.scala
@@ -0,0 +1,18 @@
+package scala
+
+package object meta {
+ def apply(x: Int): Int = x * x
+}
+
+class Test {
+ meta { 5 + 4 }
+
+ scala.meta { 3 }
+
+ scala.meta.`package` { 3 }
+
+ // val m1 = meta // error
+ // val m2 = scala.meta // error
+ val m3 = scala.meta.`package`
+ val m4 = meta.`package`
+}