diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index c7f9c762e440..7694a7cc240a 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -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) diff --git a/compiler/src/dotty/tools/dotc/typer/Checking.scala b/compiler/src/dotty/tools/dotc/typer/Checking.scala index 0525ce805d2e..6e8fa8b9c9d8 100644 --- a/compiler/src/dotty/tools/dotc/typer/Checking.scala +++ b/compiler/src/dotty/tools/dotc/typer/Checking.scala @@ -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 = diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index a85b2574e59c..ac8d6152812e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -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() diff --git a/tests/neg/i12537.scala b/tests/neg/i12537.scala new file mode 100644 index 000000000000..f6c6347bf47e --- /dev/null +++ b/tests/neg/i12537.scala @@ -0,0 +1,2 @@ +extension [T](x: T) def ext: T = x +def foo = String.ext // error diff --git a/tests/neg/i7750.scala b/tests/neg/i7750.scala index 6b29a6e68640..bdbe3b8f33bc 100644 --- a/tests/neg/i7750.scala +++ b/tests/neg/i7750.scala @@ -1,3 +1,3 @@ -package object A extends runtime.A { +package object A extends runtime.A { // error implicit def a( : ) = 1() // error // error // error } \ No newline at end of file