Skip to content

Commit d120926

Browse files
Backport "Only consider methods with 0 parameters in valueOf" to LTS (#21153)
Backports #20543 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents c192315 + 3ff5115 commit d120926

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
114114
val objectName = sym.owner.fullName.encode.toString.stripSuffix("$")
115115
val resObj: Class[?] = Class.forName(objectName, true, classLoader())
116116
val symValue = resObj
117-
.getDeclaredMethods.find(_.getName == sym.name.encode.toString)
117+
.getDeclaredMethods
118+
.find(method => method.getName == sym.name.encode.toString && method.getParameterCount == 0)
118119
.flatMap(result => rewrapValueClass(sym.info.classSymbol, result.invoke(null)))
119120
symValue
120121
.filter(_ => sym.is(Flags.Method) || sym.info != defn.UnitType)

compiler/test-resources/repl/19184

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
scala> def o(s: String) = "o"; def oo(s: String) = "oo"; val o = "o"; val oo = "oo"
2+
def o(s: String): String
3+
def oo(s: String): String
4+
val o: String = o
5+
val oo: String = oo

0 commit comments

Comments
 (0)