-
Notifications
You must be signed in to change notification settings - Fork 1.1k
move 'return outside method definition' to error class #3173
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
Conversation
@enru Will need to be rebased. Conflicts with the merge of your other PR |
case class ReturnOutsideMethodDefinition()(implicit ctx: Context) | ||
extends Message(ReturnOutsideMethodDefinitionID) { | ||
val kind = "Syntax" | ||
val msg = s"return outside method definition" |
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 would turn the phrasing around and say that retrun
must be inside a method definition.
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 kept the wording from the original, which is the same in scalac.
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.
Ok
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.
Though we can improve
val kind = "Syntax" | ||
val msg = s"return outside method definition" | ||
val explanation = | ||
hl"${"return"} is a keyword and may only be used within methods" |
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.
Here I would explain where the return vas found (i.e. in ctx.owner
if it is not NoContext
)
extends Message(ReturnOutsideMethodDefinitionID) { | ||
val kind = "Syntax" | ||
val msg = hl"${"return"} outside method definition" | ||
private val contextInfo = |
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.
Should probably be a def
@@ -980,7 +980,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit | |||
def enclMethInfo(cx: Context): (Tree, Type) = { | |||
val owner = cx.owner | |||
if (cx == NoContext || owner.isType) { |
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.
@nicolasstucki I'm curious. Does it ever happen to have NoContext
here?
Can your rebase on top of master. Also you can now define the message as follow: case class ReturnOutsideMethodDefinition(owner: Symbol)(implicit ctx: Context)
extends Message(ReturnOutsideMethodDefinitionID) {
val kind = "Syntax"
val msg = hl"${"return"} outside method definition"
val explanation =
hl"""You used ${"return"} in ${owner.show}".
|${"return"} is a keyword and may only be used within method declarations.
|"""
} |
So I understand, the |
No, |
This reverts commit 1943f4e.
Workaround sbt/sbt#3580 by not using Def.derive
Inspired from the cats documentation The button color is changed to gray to make it less intrusive
`return` outside a type definition would result in a parsing error. Therefore the context cannot be `NoContext`.
Sorry, looks like git and I didn't come along that well. |
@felixmulder Long time, no commit.