-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2512: Implicit keyword not allowed on return types #2523
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
@@ -771,6 +776,9 @@ object Parsers { | |||
} | |||
else infixType() | |||
|
|||
if (isImplicit && !isImplicitFun && in.token != ARROW) | |||
syntaxError("Types with implicit keyword can only be function types", start, nme.IMPLICITkw) | |||
|
|||
in.token match { | |||
case ARROW => functionRest(t :: Nil) | |||
case FORSOME => syntaxError(ExistentialTypesNoLongerSupported()); t |
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 you can avoid the isImplicitFun
logic and simply change the next line to:
case _ =>
if (isImplicit) syntaxError("Types with implicit keyword can only be function types", start)
t
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.
Even if not, it will eliminate the in.token != ARROW
@@ -116,9 +116,9 @@ object Parsers { | |||
/** Issue an error at given offset if beyond last error offset | |||
* and update lastErrorOffset. | |||
*/ | |||
def syntaxError(msg: => Message, offset: Int = in.offset): Unit = | |||
def syntaxError(msg: => Message, offset: Int = in.offset, name: Name = in.name): 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 think it is a bit overkill to add another parameter here.
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.
Then use directly syntaxError(msg, Position(offset, offset + length))
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 add length at all?
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.
Restored it, where length = the length of implicit keyword
, otherwise it is the length of the identifier (in this case 3, from Int
).
@@ -771,6 +776,9 @@ object Parsers { | |||
} | |||
else infixType() | |||
|
|||
if (isImplicit && !isImplicitFun && in.token != ARROW) | |||
syntaxError("Types with implicit keyword can only be function types", Position(start, start + nme.IMPLICITkw.asSimpleName.length)) |
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 asSimpleName
?
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.
Just to get the length. Any alternative way?
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 is fine
Update Parser to accommodate the new checks
Thanks @nicolasstucki for pair programming!