From 2d37cc0b846a0ba50eb534c2a7379efd95f72ebc Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Mon, 21 Apr 2014 23:39:16 +0300 Subject: makes bundles friendly to -Ywarn-dead-code Apparently, the `new Bundle(???).impl` synthetic tree generated as a macro impl ref for bundles evokes -Ywarn-dead-code warnings. This pull requests changes `???` to `null` in order not to stress out the checker. What's in the argument doesn't actually make any difference anyway. --- src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala index 1413065a27..a13a778b2f 100644 --- a/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala +++ b/src/compiler/scala/reflect/macros/compiler/DefaultMacroCompiler.scala @@ -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) -- cgit v1.2.3 From 8317266f34dce29078dc7c4447605701ba82e82a Mon Sep 17 00:00:00 2001 From: François Garillot Date: Fri, 25 Apr 2014 15:52:50 +0200 Subject: SI-8537 Puts SI-8157 fix under Xsource --- src/compiler/scala/tools/nsc/typechecker/RefChecks.scala | 11 ++++++++++- test/files/pos/t8157-2.10.flags | 1 + test/files/pos/t8157-2.10.scala | 5 +++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t8157-2.10.flags create mode 100644 test/files/pos/t8157-2.10.scala (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index b166bf988d..4540017b62 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -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) diff --git a/test/files/pos/t8157-2.10.flags b/test/files/pos/t8157-2.10.flags new file mode 100644 index 0000000000..94c8056747 --- /dev/null +++ b/test/files/pos/t8157-2.10.flags @@ -0,0 +1 @@ +-Xsource:2.10 diff --git a/test/files/pos/t8157-2.10.scala b/test/files/pos/t8157-2.10.scala new file mode 100644 index 0000000000..597585a96d --- /dev/null +++ b/test/files/pos/t8157-2.10.scala @@ -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 = ??? +} -- cgit v1.2.3 From ecbc9d02153e9ad3a710c7c2c0f385797b1ba3a6 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 5 May 2014 11:32:43 +0200 Subject: SI-8549 Honour the @SerialVersionUID annotatation In PR #1673 / 4267444, the annotation `SerialVersionId` was changed from a `StaticAnnotation` to `ClassFileAnnotation` in order to avoid silently ignoring non-literal UIDs like: @SerialVersionUID(0 - 12345L) class C And to flag non-constant UIDs: @SerialVersionUID("!!!".length) While this indeed was fold constants, the change was incomplete. The compiler API for reading the argument from a `ClassFileAnnoation` is different, on must look for a `LiteralAnnotArg`, rather than a `Literal`. This commit: - amends the backend accordingly - removes relevant duplication between `GenASM` and `GenBCode` - tests that the static field is generated accordingly This will mean that we will break deserialization of objects from Scalal 2.11.0 that use this annotation. --- .../scala/tools/nsc/backend/jvm/BCodeHelpers.scala | 14 +++++++------- src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala | 4 +--- test/files/run/t8549b.scala | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 10 deletions(-) create mode 100644 test/files/run/t8549b.scala (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala index 359e5d6c29..f800dbf9cd 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/BCodeHelpers.scala @@ -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) @@ -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` * diff --git a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala index a389816caf..b7f9b30e19 100644 --- a/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala +++ b/src/compiler/scala/tools/nsc/backend/jvm/GenASM.scala @@ -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] = { diff --git a/test/files/run/t8549b.scala b/test/files/run/t8549b.scala new file mode 100644 index 0000000000..1e1bf2c0bc --- /dev/null +++ b/test/files/run/t8549b.scala @@ -0,0 +1,16 @@ + +@SerialVersionUID(42) +class C + +@SerialVersionUID(43 - 1) +class D + + +object Test extends App { + def checkId(cls: Class[_]) { + val id = cls.getDeclaredField("serialVersionUID").get(null) + assert(id == 42, (cls, id)) + } + checkId(classOf[C]) + checkId(classOf[D]) +} -- cgit v1.2.3 From b0fe13505faf7c93093b4e9dc2813259e2f70094 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Sun, 23 Feb 2014 02:37:09 -0800 Subject: SI-8325 Accept infix star type outside patterns This is a follow-up to SI-5702 which enabled use of `*` in infix notation in patterns. Most of the work is in distinguishing infix from a sequence pattern. Also, do not take backticked star as the repeated parameter marker in postfix position. That is, `Int``*``` is not `Int*` -- I hope double-tick renders as tick. There is not a special use case except that backticks mean "I am an identifier, as is, and not a keyword." --- .../scala/tools/nsc/ast/parser/Parsers.scala | 30 +++++++++++++++------- test/files/neg/t8325-b.check | 10 ++++++++ test/files/neg/t8325-b.scala | 4 +++ test/files/neg/t8325-c.check | 7 +++++ test/files/neg/t8325-c.scala | 4 +++ test/files/neg/t8325.check | 15 +++++++++++ test/files/neg/t8325.scala | 11 ++++++++ test/files/pos/t8325.scala | 9 +++++++ 8 files changed, 81 insertions(+), 9 deletions(-) create mode 100644 test/files/neg/t8325-b.check create mode 100644 test/files/neg/t8325-b.scala create mode 100644 test/files/neg/t8325-c.check create mode 100644 test/files/neg/t8325-c.scala create mode 100644 test/files/neg/t8325.check create mode 100644 test/files/neg/t8325.scala create mode 100644 test/files/pos/t8325.scala (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 9e631febee..ffc45b21ea 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -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 @@ -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 } /** {{{ diff --git a/test/files/neg/t8325-b.check b/test/files/neg/t8325-b.check new file mode 100644 index 0000000000..ec80826dc0 --- /dev/null +++ b/test/files/neg/t8325-b.check @@ -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 diff --git a/test/files/neg/t8325-b.scala b/test/files/neg/t8325-b.scala new file mode 100644 index 0000000000..6ac78708bb --- /dev/null +++ b/test/files/neg/t8325-b.scala @@ -0,0 +1,4 @@ + +trait Test { + def k(is: Int*} = ??? +} diff --git a/test/files/neg/t8325-c.check b/test/files/neg/t8325-c.check new file mode 100644 index 0000000000..51ea4988a6 --- /dev/null +++ b/test/files/neg/t8325-c.check @@ -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 diff --git a/test/files/neg/t8325-c.scala b/test/files/neg/t8325-c.scala new file mode 100644 index 0000000000..076202df3f --- /dev/null +++ b/test/files/neg/t8325-c.scala @@ -0,0 +1,4 @@ + +trait Test { + def k(xx: Int`*`) = ??? +} diff --git a/test/files/neg/t8325.check b/test/files/neg/t8325.check new file mode 100644 index 0000000000..175a0db415 --- /dev/null +++ b/test/files/neg/t8325.check @@ -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 diff --git a/test/files/neg/t8325.scala b/test/files/neg/t8325.scala new file mode 100644 index 0000000000..3813797e83 --- /dev/null +++ b/test/files/neg/t8325.scala @@ -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) = ??? +} diff --git a/test/files/pos/t8325.scala b/test/files/pos/t8325.scala new file mode 100644 index 0000000000..af33ee7bb3 --- /dev/null +++ b/test/files/pos/t8325.scala @@ -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 +} -- cgit v1.2.3