diff --git a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala index cec8570a7597..3b7d08e2525b 100644 --- a/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala @@ -181,7 +181,7 @@ class PlainPrinter(_ctx: Context) extends Printer { case tp: ErrorType => s"" case tp: WildcardType => - if (tp.optBounds.exists) "(?" ~ toTextRHS(tp.bounds) ~ ")" else "?" + if (tp.optBounds.exists) "" else "" case NoType => "" case NoPrefix => diff --git a/compiler/src/dotty/tools/dotc/transform/Erasure.scala b/compiler/src/dotty/tools/dotc/transform/Erasure.scala index 71a10cf6eb20..0d227a22bb60 100644 --- a/compiler/src/dotty/tools/dotc/transform/Erasure.scala +++ b/compiler/src/dotty/tools/dotc/transform/Erasure.scala @@ -419,15 +419,17 @@ object Erasure { /** Check that Java statics and packages can only be used in selections. */ - private def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = { - if (!proto.isInstanceOf[SelectionProto] && !proto.isInstanceOf[ApplyingProto]) { - val sym = tree.tpe.termSymbol - // The check is avoided inside Java compilation units because it always fails - // on the singleton type Module.type. - if ((sym is Flags.Package) || (sym.isAllOf(Flags.JavaModule) && !ctx.compilationUnit.isJava)) ctx.error(reporting.diagnostic.messages.JavaSymbolIsNotAValue(sym), tree.sourcePos) - } + private def checkValue(tree: Tree, proto: Type)(implicit ctx: Context): tree.type = + if (!proto.isInstanceOf[SelectionProto] && !proto.isInstanceOf[ApplyingProto]) then + checkValue(tree) tree - } + + private def checkValue(tree: Tree)(using ctx: Context): Unit = + val sym = tree.tpe.termSymbol + if (sym is Flags.Package) + || (sym.isAllOf(Flags.JavaModule) && !ctx.compilationUnit.isJava) + then + ctx.error(reporting.diagnostic.messages.JavaSymbolIsNotAValue(sym), tree.sourcePos) private def checkNotErased(tree: Tree)(implicit ctx: Context): tree.type = { if (!ctx.mode.is(Mode.Type)) { @@ -551,6 +553,8 @@ object Erasure { val sym = if (owner eq origSym.maybeOwner) origSym else owner.info.decl(tree.name).symbol assert(sym.exists, origSym.showLocated) + if owner == defn.ObjectClass then checkValue(qual1) + def select(qual: Tree, sym: Symbol): Tree = untpd.cpy.Select(tree)(qual, sym.name).withType(NamedType(qual.tpe, sym)) diff --git a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala index e1c017ad161c..f5c280ae290e 100644 --- a/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala +++ b/compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala @@ -984,22 +984,6 @@ class ErrorMessagesTests extends ErrorMessagesTest { assertEquals(err, ImplicitClassPrimaryConstructorArity()) } - @Test def anonymousFunctionMissingParamType = - checkMessagesAfter(RefChecks.name) { - """ - |object AnonymousF { - | val f = { case x: Int => x + 1 } - |}""".stripMargin - } - .expect { (ictx, messages) => - implicit val ctx: Context = ictx - - assertMessageCount(1, messages) - val AnonymousFunctionMissingParamType(param, args, _, pt) = messages.head - assertEquals("x$1", param.show) - assertEquals("?", pt.show) - } - @Test def superCallsNotAllowedInline = checkMessagesAfter(RefChecks.name) { """ diff --git a/tests/neg/i5313.scala b/tests/neg/i5313.scala new file mode 100644 index 000000000000..0add1d02dc58 --- /dev/null +++ b/tests/neg/i5313.scala @@ -0,0 +1,6 @@ +def test = + System.getClass // error + System.toString // error + System == null // error + System eq null // error + System.wait() // error