-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Closes #1731 by fixing error message for overloaded method without re… #2823
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
Closes #1731 by fixing error message for overloaded method without re… #2823
Conversation
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
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.
Thanks for taking the time to submit this PR! We really appreciate the thought going into these contributions.
There are a couple of things I'm hesitant about, but I await your response :)
OverloadedOrRecursiveMethodNeedsResultType(tree.name.toString)(ctx) | ||
def apply(symbol: Symbol)(implicit ctx: Context) | ||
: OverloadedOrRecursiveMethodNeedsResultType = | ||
OverloadedOrRecursiveMethodNeedsResultType(symbol.name.toString)(ctx) |
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.
There's a "Showable" type class that can be accessed for both trees and symbols via .show
@@ -48,7 +48,7 @@ object ProtoTypes { | |||
|
|||
private def disregardProto(pt: Type)(implicit ctx: Context): Boolean = pt.dealias match { | |||
case _: OrType => true | |||
case pt => pt.isRef(defn.UnitClass) | |||
case ptd => ptd.isRef(defn.UnitClass) |
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.
Maybe an unnecessary diff?
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.
the 'case' pt shadows the outer pt, which may not be an issue here, but could crop up later if the function became more complex, I suppose. Happy to take it out though.
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 think the point here is to specifically shadow it, we do this all over the compiler :)
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.
👍
@@ -1872,8 +1872,6 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |||
*/ | |||
def adaptInterpolated(tree: Tree, pt: Type, original: untpd.Tree)(implicit ctx: Context): Tree = { | |||
|
|||
assert(pt.exists) | |||
|
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.
Why was this assertion removed?
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.
Wow, I don't know - it shouldn't have been, sorry that typo slipped through (I really do not remember making this change, but still should have spotted it, hmm).
// val OverloadedOrRecursiveMethodNeedsResultType(treeName2) :: Nil = messages | ||
// assertEquals("Foo", treeName2) | ||
// } | ||
} |
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.
This should be fine as it is reported after the front end (of which typer is a part). Why can't this test be enabled?
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 cloned your branch and tried out the commented out test - and it runs fine for me. Did you do git submodule update --init
?
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.
Hmm, I thought I did but can't quite remember exactly which submodule command I originally ran. I tried this but it didn't make a difference. I'll uncomment for now and try to figure out my issue later.
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.
Submit it uncommented and we'll see what the CI says 😄
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.
Will do, I'm getting a number of failures from sbt test
so will see how this compares.
@@ -1320,7 +1329,8 @@ object messages { | |||
|""" | |||
} | |||
|
|||
case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type)(err: typer.ErrorReporting.Errors)(implicit ctx: Context) | |||
case class MethodDoesNotTakeParameters(tree: tpd.Tree, methPartType: Types.Type) | |||
(err: typer.ErrorReporting.Errors)(implicit ctx: Context) |
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.
👍
|""".stripMargin | ||
} | ||
|
||
object OverloadedOrRecursiveMethodNeedsResultType { | ||
@specialized def apply[T >: Trees.Untyped](tree: NameTree[T])(implicit ctx: Context) |
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.
No need for the @specialized
annotation, Dotty will have its own form of specialization that does not require the annotation. Also, the bootstrapped compiler currently doesn't do anything for @specialized
.
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.
👍
@@ -1209,20 +1209,29 @@ object messages { | |||
|""".stripMargin | |||
} | |||
|
|||
case class OverloadedOrRecursiveMethodNeedsResultType(tree: Names.TermName)(implicit ctx: Context) | |||
case class OverloadedOrRecursiveMethodNeedsResultType private (termName: String)(implicit ctx: Context) |
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.
Why make the name private? If you're an IDE, wouldn't you want to be able to extract the name from the message?
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.
My thought was to prevent accidental use that might happen by passing in a string directly; I may not understand all the implications, but even with private it seems I can still extract the string in ErrorMessagesTests.scala
:
val OverloadedOrRecursiveMethodNeedsResultType(treeName) :: Nil = messages
assertEquals("i", treeName)
Seems to work
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.
Hmm, I did correct this before having coffee. Ignore this comment, it's just the constructor marked private, not the members ☕️
@@ -126,7 +126,7 @@ object Contexts { | |||
protected def sstate_=(sstate: SettingsState) = _sstate = sstate | |||
def sstate: SettingsState = _sstate | |||
|
|||
/** The current tree */ | |||
/** The current compilation unit */ |
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 thinking about revising the commit message to "fixes for #1731" instead of "closes", and just update the issue. I'll plan to come back to it soon for a full fix. |
…hod without return type
3bc3c31
to
30ac9e2
Compare
Looks like it ran just fine - except that the test fails with: recursiveMethodNeedsReturnType failed:
org.junit.ComparisonFailure: expected:<[i]> but was:<[def i = i + 5]>
// and
overloadedMethodNeedsReturnType failed:
org.junit.ComparisonFailure: expected:<[foo]> but was:<[def foo(i: Int) = foo(i.toString)]> hint: tree.show // string of tree as "scala-like" code
tree.name.show // string of name without encodings |
Thanks again for the review ,and the help. I reviewed the dotty build instructions and started afresh on another system; I think the Unfortunately, I still get the error for this test as originally reported in #1731, and now I seem to have managed (by means unknown) to have gotten the CI build system to replicate the issue:
|
That's great, I should be able to reproduce it now! |
#2832 should have fixed your issue! :) |
Thanks @felixmulder - looks like CI is happy now |
@bbarker it does indeed! I'm sorry this fell through the cracks, I went on vacation and simply haven't gotten around to merging this until today. So, again, sorry for the belated merge, and thanks a bunch for contributing! 🎉 |
…od without re… (scala#2823)" This reverts commit 91d3ec1.
This was achieved by adding a more specific conditional to note the specific error and by overloading apply for the already existing
OverloadedOrRecursiveMethodNeedsResultType
.While this is an improvement, it is still not quite right, as the error message now behaves like:
To improve beyond this, it seems we would need some way to walk up the tree to get to the LHS (not sure if possible), or, catch it higher up the tree in the first place.