-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #3408 Implement SIP-27: Trailing Commas #3463
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
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.
Hello, and thank you for opening this PR! 🎉
All contributors have signed the CLA, thank you! ❤️
Have an awesome day! ☀️
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.
Thanks a lot for your contribution @CucumisSativus ! For the import problem, you can try some changes in the parser as follows:
--- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
+++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala
@@ -1961,10 +1961,10 @@ object Parsers {
/** ImportSelectors ::= `{' {ImportSelector `,'} (ImportSelector | `_') `}'
*/
- def importSelectors(): List[Tree] =
- if (in.token == RBRACE) Nil
+ def importSelectors(): List[Tree] = {
+ val sel = importSelector()
+ if (in.token == RBRACE) sel :: Nil
else {
- val sel = importSelector()
sel :: {
if (!isWildcardArg(sel) && in.token == COMMA) {
in.nextToken()
@@ -1973,6 +1973,7 @@ object Parsers {
else Nil
}
}
+ }
trait ArgumentExprs1 { f(23, "bar", )(Ev0, Ev1) } // error // error | ||
trait ArgumentExprs2 { f(23, "bar")(Ev0, Ev1, ) } // error // error | ||
trait ArgumentExprs3 { new C(23, "bar", )(Ev0, Ev1) } // error // error | ||
trait ArgumentExprs4 { new C(23, "bar")(Ev0, Ev1, ) } // error // error |
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 would be nice to avoid undefined identifiers so that we only get errors about trailing commas. Same for the code below.
Scanner implemented to accept trailing commas before new line Based on SI-4986 Allow trailing commas before newlines from scala repository
8924715
to
21f529b
Compare
hey @liufengyun i hope i resolved the issues you addressed + your fix to |
|
||
// Multi-line only cases: make sure trailing commas are only supported when multi-line | ||
|
||
trait ArgumentExprs1 { validMethod(23, "bar", )(Ev0, Ev1) } // error // error |
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.
What are the two errors emitted here? One is the invalid trailing comma. What is the other one?
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.
The first one is illegal start of simple expression
. The second is as follow
5 |trait ArgumentExprs1 { validMethod(23, "bar", )(Ev0, Ev1) } // error // error
| ^
|too many arguments for method validMethod: (foo: Int, bar: String)(implicit ev0: foo.package.Ev0, ev1: foo.package.Ev1): Int
LGTM, thanks a lot @CucumisSativus ! |
Thank @liufengyun and @allanrenucci for your time :) |
Scanner implemented to accept trailing commas before new line, implementation form scala repo scala/scala#5245
There is one negative case which should fail, but does not
trait ImportSelectors { import foo.{ Ev0, Ev1, } }
Would appreciate any help there
The rest seams to be working, but I would be glad if you could double check my tests