Skip to content

Try fix #1786: support use package object as value #1787

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
17 changes: 17 additions & 0 deletions tests/neg/i1786.scala
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions tests/pos/i1786.scala
Original file line number Diff line number Diff line change
@@ -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`
}