-
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
Changes from all commits
30ac9e2
6c334e1
0d8d1ca
16be5c5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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
Seems to work There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 ☕️ |
||
extends Message(OverloadedOrRecursiveMethodNeedsResultTypeID) { | ||
val kind = "Syntax" | ||
val msg = hl"""overloaded or recursive method ${tree} needs return type""" | ||
val msg = hl"""overloaded or recursive method $termName needs return type""" | ||
val explanation = | ||
hl"""Case 1: ${tree} is overloaded | ||
|If there are multiple methods named `${tree.name}` and at least one definition of | ||
hl"""Case 1: $termName is overloaded | ||
|If there are multiple methods named `$termName` and at least one definition of | ||
|it calls another, you need to specify the calling method's return type. | ||
| | ||
|Case 2: ${tree} is recursive | ||
|If `${tree.name}` calls itself on any path, you need to specify its return type. | ||
|Case 2: $termName is recursive | ||
|If `$termName` calls itself on any path, you need to specify its return type. | ||
|""".stripMargin | ||
} | ||
|
||
object OverloadedOrRecursiveMethodNeedsResultType { | ||
def apply[T >: Trees.Untyped](tree: NameTree[T])(implicit ctx: Context) | ||
: OverloadedOrRecursiveMethodNeedsResultType = | ||
OverloadedOrRecursiveMethodNeedsResultType(tree.name.show)(ctx) | ||
def apply(symbol: Symbol)(implicit ctx: Context) | ||
: OverloadedOrRecursiveMethodNeedsResultType = | ||
OverloadedOrRecursiveMethodNeedsResultType(symbol.name.show)(ctx) | ||
} | ||
|
||
case class RecursiveValueNeedsResultType(tree: Names.TermName)(implicit ctx: Context) | ||
extends Message(RecursiveValueNeedsResultTypeID) { | ||
val kind = "Syntax" | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
extends Message(MethodDoesNotTakeParametersId) { | ||
private val more = tree match { | ||
case Apply(_, _) => " more" | ||
|
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.
❤️