Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only consider methods with 0 parameters in valueOf #20543

Merged
merged 1 commit into from
Jul 1, 2024

Conversation

mbovel
Copy link
Member

@mbovel mbovel commented Jun 10, 2024

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

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
@mbovel mbovel requested a review from rochala June 10, 2024 15:06
Copy link
Contributor

@rochala rochala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left a comment, but it is not exactly connected to the PR you've made, so feel free to merge it.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we're handling Flags.Method

If this method is used solely for rendering value definitions maybe we should rename it ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering why we're handling Flags.Method.

This seems to date back to e4241d5: "Only evaluate side-effecty expression once".

By the way, I find the filter with an unused argument introduced in 302aaca confusing (cc @som-snytt).

If this method is used solely for rendering value definitions maybe we should rename it ?

Agreed.

@mbovel
Copy link
Member Author

mbovel commented Jul 1, 2024

I left a comment, but it is not exactly connected to the PR you've made, so feel free to merge it.

Thanks for your review!

I agree with what you wrote, but I also think we should keep the diff minimal for now. Let's maybe keep these potential improvements in mind for the future.

@mbovel mbovel merged commit 4828244 into scala:main Jul 1, 2024
19 checks passed
@mbovel mbovel deleted the mb/19184 branch July 1, 2024 11:23
@Kordyjan Kordyjan added this to the 3.5.1 milestone Jul 3, 2024
WojciechMazur pushed a commit that referenced this pull request Jul 10, 2024
`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]
WojciechMazur pushed a commit that referenced this pull request Jul 10, 2024
`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]
WojciechMazur added a commit that referenced this pull request Jul 10, 2024
…21153)

Backports #20543 to the LTS branch.

PR submitted by the release tooling.
[skip ci]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants