From 48282440b243c9c7aa41c104f0124dd1dfe2e2a2 Mon Sep 17 00:00:00 2001 From: Matt Bovel Date: Mon, 1 Jul 2024 13:22:34 +0200 Subject: [PATCH] Only consider methods with 0 parameters in valueOf (#20543) `valueOf` should only consider getters, which have 0 parameters. test with: ``` scala3-compiler / testOnly dotty.tools.repl.ScriptedTests -- dotty.tools.repl.ScriptedTests.replTests ``` Fixes #19184 --- compiler/src/dotty/tools/repl/Rendering.scala | 3 ++- compiler/test-resources/repl/19184 | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 compiler/test-resources/repl/19184 diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index d5688d1038b4..c127cc959e25 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -115,7 +115,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None): val objectName = sym.owner.fullName.encode.toString.stripSuffix("$") val resObj: Class[?] = Class.forName(objectName, true, classLoader()) val symValue = resObj - .getDeclaredMethods.find(_.getName == sym.name.encode.toString) + .getDeclaredMethods + .find(method => method.getName == sym.name.encode.toString && method.getParameterCount == 0) .flatMap(result => rewrapValueClass(sym.info.classSymbol, result.invoke(null))) symValue .filter(_ => sym.is(Flags.Method) || sym.info != defn.UnitType) diff --git a/compiler/test-resources/repl/19184 b/compiler/test-resources/repl/19184 new file mode 100644 index 000000000000..cf4ce6f1d22f --- /dev/null +++ b/compiler/test-resources/repl/19184 @@ -0,0 +1,5 @@ +scala> def o(s: String) = "o"; def oo(s: String) = "oo"; val o = "o"; val oo = "oo" +def o(s: String): String +def oo(s: String): String +val o: String = o +val oo: String = oo