-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Conversation
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
There was a problem hiding this 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) |
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
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. |
valueOf
should only consider getters, which have 0 parameters.test with:
Fixes #19184