Skip to content

Commit ba48e7f

Browse files
committed
Fix #1786: support use package object as value
1 parent 7775aab commit ba48e7f

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

+3
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,9 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
357357
}
358358

359359
val tree1 = ownType match {
360+
case ownType: NamedType if ownType.symbol.is(Package) && !pt.isInstanceOf[SelectionProto] =>
361+
val pkgObj = ownType.symbol.moduleClass.denot.asInstanceOf[PackageClassDenotation].packageObj
362+
if (pkgObj.exists) ref(pkgObj.valRef) else tree.withType(ownType)
360363
case ownType: NamedType if !prefixIsElidable(ownType) =>
361364
ref(ownType).withPos(tree.pos)
362365
case _ =>

tests/pos/i1786.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package object meta {
2+
def apply(x: Int): Int = x * x
3+
}
4+
5+
class Test {
6+
def f = meta {
7+
5 + 4
8+
}
9+
10+
meta
11+
}

0 commit comments

Comments
 (0)