Skip to content

Commit 4828244

Browse files
authored
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
1 parent 3d16f33 commit 4828244

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
@@ -115,7 +115,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None):
115115
val objectName = sym.owner.fullName.encode.toString.stripSuffix("$")
116116
val resObj: Class[?] = Class.forName(objectName, true, classLoader())
117117
val symValue = resObj
118-
.getDeclaredMethods.find(_.getName == sym.name.encode.toString)
118+
.getDeclaredMethods
119+
.find(method => method.getName == sym.name.encode.toString && method.getParameterCount == 0)
119120
.flatMap(result => rewrapValueClass(sym.info.classSymbol, result.invoke(null)))
120121
symValue
121122
.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)