Skip to content

Don't try conversions or extensions on Java companion objects #14881

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 2 commits into from
Apr 8, 2022
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: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/SymUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ object SymUtils:

def isSuperAccessor(using Context): Boolean = self.name.is(SuperAccessorName)

def isNoValue(using Context): Boolean = self.is(Package) || self.isAllOf(JavaModule)

/** Is this a type or term parameter or a term parameter accessor? */
def isParamOrAccessor(using Context): Boolean =
self.is(Param) || self.is(ParamAccessor)
Expand Down
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 @@ -713,7 +713,7 @@ object Checking {

def checkValue(tree: Tree)(using Context): Unit =
val sym = tree.tpe.termSymbol
if sym.is(Flags.Package) || sym.isAllOf(Flags.JavaModule) && !ctx.isJava then
if sym.isNoValue && !ctx.isJava then
report.error(JavaSymbolIsNotAValue(sym), tree.srcPos)

def checkValue(tree: Tree, proto: Type)(using Context): tree.type =
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3245,6 +3245,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
rememberSearchFailure(qual,
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))

if qual.symbol.isNoValue then return EmptyTree

// try an extension method in scope
try
val nestedCtx = ctx.fresh.setNewTyperState()
Expand Down
2 changes: 2 additions & 0 deletions tests/neg/i12537.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
extension [T](x: T) def ext: T = x
def foo = String.ext // error
2 changes: 1 addition & 1 deletion tests/neg/i7750.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package object A extends runtime.A {
package object A extends runtime.A { // error
implicit def a( : ) = 1() // error // error // error
}