Skip to content

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

Merged
merged 1 commit into from
Nov 17, 2017

Conversation

CucumisSativus
Copy link
Contributor

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

Copy link
Member

@dottybot dottybot left a 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! ☀️

Copy link
Contributor

@liufengyun liufengyun left a 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
Copy link
Contributor

@liufengyun liufengyun Nov 14, 2017

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
@CucumisSativus
Copy link
Contributor Author

hey @liufengyun i hope i resolved the issues you addressed + your fix to importSelectors() worked like a charm :)


// Multi-line only cases: make sure trailing commas are only supported when multi-line

trait ArgumentExprs1 { validMethod(23, "bar", )(Ev0, Ev1) } // error // error
Copy link
Contributor

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?

Copy link
Contributor Author

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

@liufengyun
Copy link
Contributor

LGTM, thanks a lot @CucumisSativus !

@liufengyun liufengyun merged commit b95e71a into scala:master Nov 17, 2017
@CucumisSativus
Copy link
Contributor Author

Thank @liufengyun and @allanrenucci for your time :)

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