Skip to content

Commit df662e5

Browse files
mbovelWojciechMazur
authored andcommitted
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 [Cherry-picked 4828244]
1 parent 5f1c3c2 commit df662e5

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)