Skip to content

Commit 686f9da

Browse files
authored
Merge pull request #14881 from dotty-staging/fix-12537
Don't try conversions or extensions on Java companion objects
2 parents 31f871c + 06ab794 commit 686f9da

File tree

5 files changed

+8
-2
lines changed

5 files changed

+8
-2
lines changed

compiler/src/dotty/tools/dotc/transform/SymUtils.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ object SymUtils:
6464

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

67+
def isNoValue(using Context): Boolean = self.is(Package) || self.isAllOf(JavaModule)
68+
6769
/** Is this a type or term parameter or a term parameter accessor? */
6870
def isParamOrAccessor(using Context): Boolean =
6971
self.is(Param) || self.is(ParamAccessor)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -713,7 +713,7 @@ object Checking {
713713

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

719719
def checkValue(tree: Tree, proto: Type)(using Context): tree.type =

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3245,6 +3245,8 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
32453245
rememberSearchFailure(qual,
32463246
SearchFailure(qual.withType(NestedFailure(ex.toMessage, selectionProto))))
32473247

3248+
if qual.symbol.isNoValue then return EmptyTree
3249+
32483250
// try an extension method in scope
32493251
try
32503252
val nestedCtx = ctx.fresh.setNewTyperState()

tests/neg/i12537.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
extension [T](x: T) def ext: T = x
2+
def foo = String.ext // error

tests/neg/i7750.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
package object A extends runtime.A {
1+
package object A extends runtime.A { // error
22
implicit def a( : ) = 1() // error // error // error
33
}

0 commit comments

Comments
 (0)