Skip to content

Commit

Permalink
Only consider methods with 0 parameters in valueOf (scala#20543)
Browse files Browse the repository at this point in the history
`valueOf` should only consider getters, which have 0 parameters.

test with:
```
scala3-compiler / testOnly dotty.tools.repl.ScriptedTests -- dotty.tools.repl.ScriptedTests.replTests
```

Fixes scala#19184
  • Loading branch information
mbovel committed Jul 1, 2024
1 parent 3d16f33 commit 4828244
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/19184
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4828244

Please sign in to comment.