-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Convert "method has return statement; needs result type" to new error format with MissingReturnTypeWithReturnStatement #3094
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 1 commit
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 |
|---|---|---|
|
|
@@ -598,6 +598,21 @@ object messages { | |
| |}""" | ||
| } | ||
|
|
||
| case class MissingReturnTypeWithReturnStatement(method: Symbol)(implicit ctx: Context) | ||
| extends Message(MissingReturnTypeWithReturnStatementID) { | ||
| val kind = "Syntax" | ||
| val msg = hl"$method has a return statement; it needs a result type" | ||
| val explanation = | ||
| hl"""|If a method contains a ${"return"} statement, it must have a return | ||
| |type explicitly given to it. For example: | ||
| | | ||
| |${"def bad() = { return \"fail\" }"} | ||
|
||
| | | ||
| |This is illegal because bad does not have a return type given | ||
| |to it. Giving bad a return type of ${"String"} will resolve | ||
| |this error.""" | ||
| } | ||
|
|
||
| case class YieldOrDoExpectedInForComprehension()(implicit ctx: Context) | ||
| extends Message(YieldOrDoExpectedInForComprehensionID) { | ||
| val kind = "Syntax" | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -955,4 +955,21 @@ class ErrorMessagesTests extends ErrorMessagesTest { | |
|
|
||
| assertEquals(ExpectedStartOfTopLevelDefinition(), err) | ||
| } | ||
|
|
||
| @Test def missingReturnTypeWithReturnStatement = | ||
| checkMessagesAfter("frontend") { | ||
| """class BadFunction { | ||
| | def bad() = { return "fail" } | ||
| |} | ||
| """.stripMargin | ||
| }.expect { (ictx, messages) => | ||
| implicit val ctx: Context = ictx | ||
| val defn = ictx.definitions | ||
|
||
|
|
||
| assertMessageCount(1, messages) | ||
|
|
||
| val MissingReturnTypeWithReturnStatement(method) :: Nil = messages | ||
|
|
||
| assertEquals(method.name.toString, "bad") | ||
|
||
| } | ||
| } | ||
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.
...it must have an explicit result type. For example: