Skip to content

Commit 19bc03c

Browse files
authored
Merge pull request #1787 from dotty-staging/fix-i1786
Try fix #1786: support use package object as value
2 parents 7775aab + 31337d5 commit 19bc03c

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ trait Checking {
418418
/** Check that Java statics and packages can only be used in selections.
419419
*/
420420
def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = {
421-
if (!proto.isInstanceOf[SelectionProto]) {
421+
if (!proto.isInstanceOf[SelectionProto] && !proto.isInstanceOf[ApplyingProto]) {
422422
val sym = tree.tpe.termSymbol
423423
// The check is avoided inside Java compilation units because it always fails
424424
// on the singleton type Module.type.

tests/neg/i1786.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package scala
2+
3+
package object meta {
4+
def apply(x: Int): Int = x * x
5+
}
6+
7+
class Test {
8+
def f(a: Any): Any = f(meta) // error
9+
def g(a: Any): Any = f(scala.meta) // error
10+
11+
meta { 5 + 4 }
12+
13+
scala.meta { 3 }
14+
15+
val m1 = meta // error
16+
val m2 = scala.meta // error
17+
}

tests/pos/i1786.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package scala
2+
3+
package object meta {
4+
def apply(x: Int): Int = x * x
5+
}
6+
7+
class Test {
8+
meta { 5 + 4 }
9+
10+
scala.meta { 3 }
11+
12+
scala.meta.`package` { 3 }
13+
14+
// val m1 = meta // error
15+
// val m2 = scala.meta // error
16+
val m3 = scala.meta.`package`
17+
val m4 = meta.`package`
18+
}

0 commit comments

Comments
 (0)