diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 0c5a8e5dbcdf..d80dfe7c051a 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 000000000000..7bf513ed88c8 --- /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 000000000000..3b1d3af52c90 --- /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` +}