Skip to content

Fix varargs in methods #2135

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 4 commits into from
Mar 22, 2017
Merged

Fix varargs in methods #2135

merged 4 commits into from
Mar 22, 2017

Conversation

mielientiev
Copy link
Contributor

Fix for issue: #1625

  • added varargs check after method's parameter parsing

Copy link
Contributor

@felixmulder felixmulder left a comment

Choose a reason for hiding this comment

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

LGTM for the most part! Some minor nitpicks to fix and adding a test for constructors, then merge! 🎉

@@ -153,6 +153,7 @@ class tests extends CompilerTest {
@Test def pos_anonClassSubtyping = compileFile(posDir, "anonClassSubtyping", twice)
@Test def pos_extmethods = compileFile(posDir, "extmethods", twice)
@Test def pos_companions = compileFile(posDir, "companions", twice)
@Test def posVarargsInMethodsT1625 = compileFiles(posDir + "varargsInMethodsT1625/")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should also apply to constructors - I think your implementation supports this, I guess it's just the name that is misleading.

@@ -177,6 +178,8 @@ class tests extends CompilerTest {
@Test def neg_all = compileFiles(negDir, verbose = true, compileSubDirs = false)
@Test def neg_typedIdents() = compileDir(negDir, "typedIdents")

@Test def negVarargsInMethodsT1625 = compileFiles(negDir + "varargsInMethodsT1625/")
Copy link
Contributor

Choose a reason for hiding this comment

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

same here


case class VarArgsParamMustComeLast()(implicit ctx: Context)
extends Message(IncorrectRepeatedParameterSyntaxID) {
override def msg: String = "*-parameter must come last"
Copy link
Contributor

Choose a reason for hiding this comment

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

let's say "varargs parameter must come last", mixing symbols and text like this feels kind of weird IMO

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just copied error message from Scala Compiler :)

@@ -4,23 +4,24 @@ package parsing

import scala.collection.mutable.ListBuffer
import scala.collection.immutable.BitSet
import util.{ SourceFile, SourcePosition }
import util.{SourceFile, SourcePosition}
Copy link
Contributor

Choose a reason for hiding this comment

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

also - these changes here - are they done by your editor or by you? I'd leave them out of the diff

import ast.Trees._
import Decorators._
import StdNames._
import util.Positions._
import Constants._
import ScriptParsers._
import Comments._
import scala.annotation.{tailrec, switch}

import scala.annotation.{switch, tailrec}
Copy link
Contributor

Choose a reason for hiding this comment

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

same with this, if you intended to move this so that scala imports are separate from internal imports, then this should be at the top with the other one. Otherwise let's get rid off this change.

@@ -0,0 +1,3 @@
trait T1 {
def foo(x: String*, y: String): Int // error: *-parameter must come last
Copy link
Contributor

Choose a reason for hiding this comment

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

also - just an FYI, the ": error text here" part of the comment is not parsed in any way (currently)

no need to change or anything

Fix case for constructor. Move `checkVarArgsRules` to `paramClauses`
@felixmulder felixmulder merged commit 5fd7a95 into scala:master Mar 22, 2017
@felixmulder
Copy link
Contributor

Thanks @mielientiev! 🎉

@@ -177,6 +178,8 @@ class tests extends CompilerTest {
@Test def neg_all = compileFiles(negDir, verbose = true, compileSubDirs = false)
@Test def neg_typedIdents() = compileDir(negDir, "typedIdents")

@Test def negVarargsT1625 = compileFiles(negDir + "varargsInMethodsT1625/")
Copy link
Contributor

Choose a reason for hiding this comment

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

This is an unnecessary complication, just put your test sources in tests/neg/ and remove this @Test def .... Also use the prefix i1625 for the test sources.

Copy link
Contributor

Choose a reason for hiding this comment

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

this is going away once we merge #2125 anyway, I'll deal with it.

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.

3 participants