Skip to content

Commit 7613234

Browse files
authored
Disallow taking singleton types of packages again (#18232)
Fixes #18109
2 parents 98b452d + 5eabaa6 commit 7613234

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

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

+8-5
Original file line numberDiff line numberDiff line change
@@ -758,13 +758,16 @@ object Checking {
758758
if sym.isNoValue && !ctx.isJava then
759759
report.error(JavaSymbolIsNotAValue(sym), tree.srcPos)
760760

761+
/** Check that `tree` refers to a value, unless `tree` is selected or applied
762+
* (singleton types x.type don't count as selections).
763+
*/
761764
def checkValue(tree: Tree, proto: Type)(using Context): tree.type =
762765
tree match
763-
case tree: RefTree
764-
if tree.name.isTermName
765-
&& !proto.isInstanceOf[SelectionProto]
766-
&& !proto.isInstanceOf[FunOrPolyProto] =>
767-
checkValue(tree)
766+
case tree: RefTree if tree.name.isTermName =>
767+
proto match
768+
case _: SelectionProto if proto ne SingletonTypeProto => // no value check
769+
case _: FunOrPolyProto => // no value check
770+
case _ => checkValue(tree)
768771
case _ =>
769772
tree
770773

tests/neg/i18109.scala

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package foo {}
2+
3+
package bar {
4+
object Test {
5+
def qux[A] = 123
6+
def main(args: Array[String]): Unit = {
7+
val y = qux[foo.type] // error
8+
val x = valueOf[foo.type] // error
9+
}
10+
}
11+
}

0 commit comments

Comments
 (0)