Compile error "star patterns must correspond with varargs parameters"

394 views
Skip to first unread message

eugene yokota

unread,
Mar 31, 2013, 3:13:05 AM3/31/13
to simple-b...@googlegroups.com
Hi,

I was porting sbt-assembly to sbt 0.13 tonight, and came across something weird.
Not sure if it's my bug, sbt 0.13's bug, or Scala 2.10's bug.

First, the plugin provides a sequence extractor called PathList that splits up file path by the system's
separator:

  object PathList {
   
private val sysFileSep = System.getProperty("file.separator")
   
def unapplySeq(path: String): Option[Seq[String]] = {
      val split
= path.split(if (sysFileSep.equals( """\""")) """\\""" else sysFileSep)
      if (split.size == 0) None
      else Some(split.toList)
    }
  }

Next, it defines a "merge strategy" based on the path[1]:

mergeStrategy in assembly := {
 
case "reference.conf" =>
   
MergeStrategy.concat
 
case PathList(ps @ _*) if isReadme(ps.last) || isLicenseFile(ps.last) =>
   
MergeStrategy.rename
 
case ....
}

The above code compiles fine for sbt 0.12, but on sbt 0.13.0-M1, it errors with the following message:

[error] /work/sbt-assembly/src/main/scala/sbtassembly/Plugin.scala:313: star patterns must correspond with varargs parameters
[error]       case PathList(ps @ _*) if isReadme(ps.last) || isLicenseFile(ps.last) =>
[error]                           ^
[error] one error found

I tried different things, and finally what fixed was moving the entire partial function out of Seq(...)
as a stand-alone function value: [2]

  val defaultMergeStrategy: String => MergeStrategy = {
   
case "reference.conf" =>
     
MergeStrategy.concat
   
case PathList(ps @ _*) if isReadme(ps.last) || isLicenseFile(ps.last) =>
     
MergeStrategy.rename
   
case ....
 
}

The code does the same thing. One is named function value, the other is an anonymous case function.
You, me, patmat, macros?

-eugene


Mark Harrah

unread,
Apr 1, 2013, 12:50:35 PM4/1/13
to simple-b...@googlegroups.com
The short answer is macros. The longer answer involves resetLocalAttrs and partial functions and a good ticket is here:

https://issues.scala-lang.org/browse/SI-6187

I'm not sure if that is a known variation or not. Perhaps you can follow up on that? The idea is to find as many of these issues as possible and get them fixed in Scala 2.10.2 and release sbt against that, but the fallback if they can't be fixed is to detect them and provide a useful error message. lazy vals are another example of things that don't work in the body of a macro that calls resetAttrs.

-Mark
> --
> You received this message because you are subscribed to the Google Groups "simple-build-tool" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to simple-build-t...@googlegroups.com.
> To post to this group, send email to simple-b...@googlegroups.com.
> Visit this group at http://groups.google.com/group/simple-build-tool?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>

eugene yokota

unread,
Apr 2, 2013, 4:58:47 AM4/2/13
to simple-b...@googlegroups.com
I reported it as SI-7320: https://issues.scala-lang.org/browse/SI-7320

-eugene
Reply all
Reply to author
Forward
0 new messages