Skip to content

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

Merged
merged 3 commits into from
May 29, 2017
Merged

Fix #2512: Implicit keyword not allowed on return types #2523

merged 3 commits into from
May 29, 2017

Conversation

biboudis
Copy link
Contributor

Update Parser to accommodate the new checks

Thanks @nicolasstucki for pair programming!

@biboudis biboudis requested a review from odersky May 24, 2017 12:37
@@ -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
Copy link
Contributor

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

Copy link
Contributor

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 =
Copy link
Contributor

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.

Copy link
Contributor

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))

Copy link
Contributor

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?

Copy link
Contributor Author

@biboudis biboudis May 24, 2017

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))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why asSimpleName?

Copy link
Contributor Author

@biboudis biboudis May 24, 2017

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is fine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants