Skip to content
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

Backport "Disallow taking singleton types of packages again" #18330

Merged
merged 1 commit into from
Aug 9, 2023
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
13 changes: 8 additions & 5 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -748,13 +748,16 @@ object Checking {
if sym.isNoValue && !ctx.isJava then
report.error(JavaSymbolIsNotAValue(sym), tree.srcPos)

/** Check that `tree` refers to a value, unless `tree` is selected or applied
* (singleton types x.type don't count as selections).
*/
def checkValue(tree: Tree, proto: Type)(using Context): tree.type =
tree match
case tree: RefTree
if tree.name.isTermName
&& !proto.isInstanceOf[SelectionProto]
&& !proto.isInstanceOf[FunOrPolyProto] =>
checkValue(tree)
case tree: RefTree if tree.name.isTermName =>
proto match
case _: SelectionProto if proto ne SingletonTypeProto => // no value check
case _: FunOrPolyProto => // no value check
case _ => checkValue(tree)
case _ =>
tree

Expand Down
11 changes: 11 additions & 0 deletions tests/neg/i18109.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package foo {}

package bar {
object Test {
def qux[A] = 123
def main(args: Array[String]): Unit = {
val y = qux[foo.type] // error
val x = valueOf[foo.type] // error
}
}
}