Skip to content

Commit

Permalink
Merge pull request scala#3729 from retronym/merge/master-to-2.11.x
Browse files Browse the repository at this point in the history
Merge master to 2.11.x
  • Loading branch information
adriaanm committed May 9, 2014
2 parents d757662 + a132314 commit d32459b
Show file tree
Hide file tree
Showing 27 changed files with 352 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ abstract class DefaultMacroCompiler extends Resolvers
(EmptyTree, TermName(""), Nil)
}
val bundleImplRef = MacroImplRefCompiler(
atPos(macroDdef.rhs.pos)(gen.mkTypeApply(Select(New(maybeBundleRef, List(List(Ident(Predef_???)))), methName), targs)),
atPos(macroDdef.rhs.pos)(gen.mkTypeApply(Select(New(maybeBundleRef, List(List(Literal(Constant(null))))), methName), targs)),
isImplBundle = true
)
val vanillaResult = tryCompile(vanillaImplRef)
Expand Down
30 changes: 21 additions & 9 deletions src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -654,9 +654,10 @@ self =>
def isIdentExcept(except: Name) = isIdent && in.name != except
def isIdentOf(name: Name) = isIdent && in.name == name

def isUnaryOp = isIdent && raw.isUnary(in.name)
def isRawStar = isIdent && in.name == raw.STAR
def isRawBar = isIdent && in.name == raw.BAR
def isUnaryOp = isIdent && raw.isUnary(in.name)
def isRawStar = isRawIdent && in.name == raw.STAR
def isRawBar = isRawIdent && in.name == raw.BAR
def isRawIdent = in.token == IDENTIFIER

def isIdent = in.token == IDENTIFIER || in.token == BACKQUOTED_IDENT
def isMacro = in.token == IDENTIFIER && in.name == nme.MACROkw
Expand Down Expand Up @@ -1001,19 +1002,30 @@ self =>
}

def infixTypeRest(t: Tree, mode: InfixMode.Value): Tree = {
if (isIdent && in.name != nme.STAR) {
val opOffset = in.offset
// Detect postfix star for repeated args.
// Only RPAREN can follow, but accept COMMA and EQUALS for error's sake.
// Take RBRACE as a paren typo.
def checkRepeatedParam = if (isRawStar) {
lookingAhead (in.token match {
case RPAREN | COMMA | EQUALS | RBRACE => t
case _ => EmptyTree
})
} else EmptyTree
def asInfix = {
val opOffset = in.offset
val leftAssoc = treeInfo.isLeftAssoc(in.name)
if (mode != InfixMode.FirstOp) checkAssoc(opOffset, in.name, leftAssoc = mode == InfixMode.LeftOp)
val op = identForType()
val tycon = atPos(opOffset) { Ident(op) }
if (mode != InfixMode.FirstOp)
checkAssoc(opOffset, in.name, leftAssoc = mode == InfixMode.LeftOp)
val tycon = atPos(opOffset) { Ident(identForType()) }
newLineOptWhenFollowing(isTypeIntroToken)
def mkOp(t1: Tree) = atPos(t.pos.start, opOffset) { AppliedTypeTree(tycon, List(t, t1)) }
if (leftAssoc)
infixTypeRest(mkOp(compoundType()), InfixMode.LeftOp)
else
mkOp(infixType(InfixMode.RightOp))
} else t
}
if (isIdent) checkRepeatedParam orElse asInfix
else t
}

/** {{{
Expand Down
14 changes: 7 additions & 7 deletions src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,13 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
cd.impl.body collect { case dd: DefDef => dd.symbol }
}

/*
* must-single-thread
*/
def serialVUID(csym: Symbol): Option[Long] = csym getAnnotation definitions.SerialVersionUIDAttr collect {
case AnnotationInfo(_, _, (_, LiteralAnnotArg(const)) :: Nil) => const.longValue
}

/*
* Populates the InnerClasses JVM attribute with `refedInnerClasses`.
* In addition to inner classes mentioned somewhere in `jclass` (where `jclass` is a class file being emitted)
Expand Down Expand Up @@ -880,13 +887,6 @@ abstract class BCodeHelpers extends BCodeTypes with BytecodeWriters {
// The particular value in use for `MIN_SWITCH_DENSITY` reflects a heuristic.
val MIN_SWITCH_DENSITY = 0.7

/*
* must-single-thread
*/
def serialVUID(csym: Symbol): Option[Long] = csym getAnnotation definitions.SerialVersionUIDAttr collect {
case AnnotationInfo(_, Literal(const) :: _, _) => const.longValue
}

/*
* Add public static final field serialVersionUID with value `id`
*
Expand Down
4 changes: 1 addition & 3 deletions src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1142,9 +1142,7 @@ abstract class GenASM extends SubComponent with BytecodeWriters with GenJVMASM {

def isParcelableClass = isAndroidParcelableClass(clasz.symbol)

def serialVUID: Option[Long] = clasz.symbol getAnnotation SerialVersionUIDAttr collect {
case AnnotationInfo(_, Literal(const) :: _, _) => const.longValue
}
def serialVUID: Option[Long] = genBCode.serialVUID(clasz.symbol)

private def getSuperInterfaces(c: IClass): Array[String] = {

Expand Down
11 changes: 10 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans

defaultMethodNames.toList.distinct foreach { name =>
val methods = clazz.info.findMember(name, 0L, requiredFlags = METHOD, stableOnly = false).alternatives
val haveDefaults = methods filter (sym => mexists(sym.info.paramss)(_.hasDefault) && !nme.isProtectedAccessorName(sym.name))
def hasDefaultParam(tpe: Type): Boolean = tpe match {
case MethodType(params, restpe) => (params exists (_.hasDefault)) || hasDefaultParam(restpe)
case _ => false
}
val haveDefaults = methods filter (
if (settings.isScala211)
(sym => mexists(sym.info.paramss)(_.hasDefault) && !nme.isProtectedAccessorName(sym.name))
else
(sym => hasDefaultParam(sym.info) && !nme.isProtectedAccessorName(sym.name))
)

if (haveDefaults.lengthCompare(1) > 0) {
val owners = haveDefaults map (_.owner)
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/LinearSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait LinearSeq[+A] extends Seq[A]
}

/** $factoryInfo
* The current default implementation of a $Coll is a `Vector`.
* The current default implementation of a $Coll is a `List`.
* @define coll linear sequence
* @define Coll `LinearSeq`
*/
Expand Down
2 changes: 1 addition & 1 deletion src/library/scala/collection/convert/Wrappers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ private[collection] trait Wrappers {
def getKey = k
def getValue = v
def setValue(v1 : B) = self.put(k, v1)
override def hashCode = byteswap32(k.hashCode) + (byteswap32(v.hashCode) << 16)
override def hashCode = byteswap32(k.##) + (byteswap32(v.##) << 16)
override def equals(other: Any) = other match {
case e: ju.Map.Entry[_, _] => k == e.getKey && v == e.getValue
case _ => false
Expand Down
3 changes: 3 additions & 0 deletions src/library/scala/reflect/Manifest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ trait Manifest[T] extends ClassManifest[T] with Equals {

// TODO undeprecated until Scala reflection becomes non-experimental
// @deprecated("Use type tags and manually check the corresponding class or type instead", "2.10.0")
@SerialVersionUID(1L)
abstract class AnyValManifest[T <: AnyVal](override val toString: String) extends Manifest[T] with Equals {
override def <:<(that: ClassManifest[_]): Boolean =
(that eq this) || (that eq Manifest.Any) || (that eq Manifest.AnyVal)
Expand All @@ -72,6 +73,7 @@ abstract class AnyValManifest[T <: AnyVal](override val toString: String) extend
case _ => false
}
override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
@transient
override val hashCode = System.identityHashCode(this)
}

Expand Down Expand Up @@ -228,6 +230,7 @@ object ManifestFactory {
private abstract class PhantomManifest[T](_runtimeClass: Predef.Class[_],
override val toString: String) extends ClassTypeManifest[T](None, _runtimeClass, Nil) {
override def equals(that: Any): Boolean = this eq that.asInstanceOf[AnyRef]
@transient
override val hashCode = System.identityHashCode(this)
}

Expand Down
7 changes: 7 additions & 0 deletions test/files/neg/t6988.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
t6988.scala:3: error: annotation argument needs to be a constant; found: 13.asInstanceOf[Long]
@SerialVersionUID(13.asInstanceOf[Long]) case class IdentifyMessage1(userName: String, user: User, code: Int)
^
t6988.scala:8: error: annotation argument needs to be a constant; found: O.SerialUID
@SerialVersionUID(O.SerialUID) case class IdentifyMessage3(userName: String, user: User, code: Int)
^
two errors found
10 changes: 10 additions & 0 deletions test/files/neg/t6988.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
case class User()

@SerialVersionUID(13.asInstanceOf[Long]) case class IdentifyMessage1(userName: String, user: User, code: Int)
@SerialVersionUID(13l) case class IdentifyMessage2(userName: String, user: User, code: Int)
object O {
val SerialUID = "13".toLong
}
@SerialVersionUID(O.SerialUID) case class IdentifyMessage3(userName: String, user: User, code: Int)


10 changes: 10 additions & 0 deletions test/files/neg/t8325-b.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
t8325-b.scala:3: error: Unmatched closing brace '}' ignored here
def k(is: Int*} = ???
^
t8325-b.scala:3: error: ';' expected but '=' found.
def k(is: Int*} = ???
^
t8325-b.scala:4: error: eof expected but '}' found.
}
^
three errors found
4 changes: 4 additions & 0 deletions test/files/neg/t8325-b.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

trait Test {
def k(is: Int*} = ???
}
7 changes: 7 additions & 0 deletions test/files/neg/t8325-c.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
t8325-c.scala:3: error: identifier expected but ')' found.
def k(xx: Int`*`) = ???
^
t8325-c.scala:4: error: ')' expected but '}' found.
}
^
two errors found
4 changes: 4 additions & 0 deletions test/files/neg/t8325-c.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

trait Test {
def k(xx: Int`*`) = ???
}
15 changes: 15 additions & 0 deletions test/files/neg/t8325.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
t8325.scala:5: error: *-parameter must come last
def f(is: Int*, s: String) = ???
^
t8325.scala:7: error: *-parameter must come last
def h(is: Int * String *, s: String) = ???
^
t8325.scala:10: error: type mismatch;
found : Int(5)
required: Int*
def j(is: Int* = 5) = ???
^
t8325.scala:10: error: a parameter section with a `*'-parameter is not allowed to have default arguments
def j(is: Int* = 5) = ???
^
four errors found
11 changes: 11 additions & 0 deletions test/files/neg/t8325.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

trait Test {
type OK[A,B] = A Tuple2 B
type *[A,B] = A Tuple2 B
def f(is: Int*, s: String) = ???
def g(is: Int * String, s: String) = ??? // OK
def h(is: Int * String *, s: String) = ???
// won't recover from following
//def i(is: Int OK) = ??? //error: identifier expected but ')' found.
def j(is: Int* = 5) = ???
}
1 change: 1 addition & 0 deletions test/files/pos/t8157-2.10.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xsource:2.10
5 changes: 5 additions & 0 deletions test/files/pos/t8157-2.10.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
object Test { // PolyTYped function default arg unicity check,
// fails in 2.11, authorized under -Xsource:2.10
def foo(printer: Any, question: => String, show: Boolean = false)(op: => Any): Any = ???
def foo[T](question: => String, show: Boolean)(op: => Any = ()): Any = ???
}
9 changes: 9 additions & 0 deletions test/files/pos/t8325.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

trait Test {
type +[A, B] = (A, B)
type *[A, B] = (A, B)

type X[A, B] = A + B
type Y[A, B] = A * B
type Z[A, B] = A `*` B
}
1 change: 1 addition & 0 deletions test/files/pos/t8523.flags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Ywarn-dead-code -Xfatal-warnings
10 changes: 10 additions & 0 deletions test/files/pos/t8523.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import scala.language.experimental.macros
import scala.reflect.macros.blackbox.Context

class Impl(val c: Context) {
def impl: c.Tree = ???
}

object Macros {
def foo: Any = macro Impl.impl
}
2 changes: 2 additions & 0 deletions test/files/run/t6988.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#1 13
#2 13
9 changes: 9 additions & 0 deletions test/files/run/t6988.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
case class User()

@SerialVersionUID(13l) case class IdentifyMessage1(userName: String, user: User, code: Int)
@SerialVersionUID(10l + 3l) case class IdentifyMessage2(userName: String, user: User, code: Int)

object Test extends App {
println("#1 " + java.io.ObjectStreamClass.lookup(IdentifyMessage1("hei", User(), 8).getClass).getSerialVersionUID)
println("#2 " + java.io.ObjectStreamClass.lookup(IdentifyMessage2("hei", User(), 8).getClass).getSerialVersionUID)
}
1 change: 1 addition & 0 deletions test/files/run/t8549.check
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
warning: there were 2 deprecation warning(s); re-run with -deprecation for details
Loading

0 comments on commit d32459b

Please sign in to comment.