summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/compiler/scala/tools/nsc/ast/parser/Parsers.scala55
-rw-r--r--src/compiler/scala/tools/nsc/transform/AddInterfaces.scala24
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala5
-rw-r--r--test/files/codelib/code.jar.desired.sha12
-rw-r--r--test/files/neg/anyval-anyref-parent.check12
-rw-r--r--test/files/neg/anyval-anyref-parent.scala4
-rw-r--r--test/files/neg/anyval-children-2.check4
-rw-r--r--test/files/neg/anyval-children-2.scala1
-rw-r--r--test/files/neg/anyval-children.check23
-rw-r--r--test/files/neg/anyval-children.scala14
-rw-r--r--test/files/scalap/caseClass/result.test2
-rw-r--r--test/files/scalap/caseObject/result.test2
12 files changed, 48 insertions, 100 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
index c2b4dc32b6..20c35e952f 100644
--- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
+++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala
@@ -2722,23 +2722,6 @@ self =>
* }}}
*/
def templateOpt(mods: Modifiers, name: Name, constrMods: Modifiers, vparamss: List[List[ValDef]], tstart: Int): Template = {
- /** Extra parents for case classes. */
- def caseParents() = (
- if (mods.isCase) {
- val arity = if (vparamss.isEmpty || vparamss.head.isEmpty) 0 else vparamss.head.size
- productConstr :: serializableConstr :: {
- Nil
- // if (arity == 0 || settings.YnoProductN.value) Nil
- // else List(
- // AppliedTypeTree(
- // productConstrN(arity),
- // vparamss.head map (vd => vd.tpt.duplicate setPos vd.tpt.pos.focus)
- // )
- // )
- }
- }
- else Nil
- )
val (parents0, argss, self, body) = (
if (in.token == EXTENDS || in.token == SUBTYPE && mods.hasTraitFlag) {
in.nextToken()
@@ -2750,29 +2733,25 @@ self =>
(List(), List(List()), self, body)
}
)
-
+ def anyrefParents() = {
+ val caseParents = if (mods.isCase) List(productConstr, serializableConstr) else Nil
+ parents0 ::: caseParents match {
+ case Nil => List(scalaAnyRefConstr)
+ case ps => ps
+ }
+ }
+ def anyvalConstructor() = (
+ // Not a well-formed constructor, has to be finished later - see note
+ // regarding AnyVal constructor in AddInterfaces.
+ DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(Nil), TypeTree(), Block(Nil, Literal(Constant())))
+ )
val tstart0 = if (body.isEmpty && in.lastOffset < tstart) in.lastOffset else tstart
+
atPos(tstart0) {
- if (inScalaPackage && name == tpnme.AnyVal) {
- // Not a well-formed constructor, has to be finished later - see note
- // regarding AnyVal constructor in AddInterfaces.
- val constructor = DefDef(NoMods, nme.CONSTRUCTOR, Nil, List(Nil), TypeTree(), Block(Nil, Literal(Constant())))
- Template(parents0, self, constructor :: body)
- }
- else if (isPrimitiveType(name))
- Template(List(scalaAnyValConstr), self, body)
- else if (parents0 exists isReferenceToAnyVal) {
- // @inline and other restrictions enforced in refchecks
- Template(parents0, self, body)
- }
- else {
- val casePs = caseParents()
- val parents = parents0 match {
- case Nil if casePs.isEmpty => List(scalaAnyRefConstr)
- case _ => parents0 ++ casePs
- }
- Template(parents, self, constrMods, vparamss, argss, body, o2p(tstart))
- }
+ if ((inScalaPackage && name == tpnme.AnyVal) || (parents0 exists isReferenceToAnyVal))
+ Template(parents0, self, anyvalConstructor :: body)
+ else
+ Template(anyrefParents, self, constrMods, vparamss, argss, body, o2p(tstart))
}
}
diff --git a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
index e7759f1d7e..531a475bc6 100644
--- a/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
+++ b/src/compiler/scala/tools/nsc/transform/AddInterfaces.scala
@@ -302,21 +302,19 @@ abstract class AddInterfaces extends InfoTransform {
yield mixinConstructorCall(implClass(mc))
}
tree match {
+ case Block(Nil, expr) =>
+ // AnyVal constructor - have to provide a real body so the
+ // jvm doesn't throw a VerifyError. But we can't add the
+ // body until now, because the typer knows that Any has no
+ // constructor and won't accept a call to super.init.
+ assert((clazz isSubClass AnyValClass) || clazz.info.parents.isEmpty, clazz)
+ val superCall = Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), Nil)
+ Block(List(superCall), expr)
+
case Block(stats, expr) =>
// needs `hasSymbol` check because `supercall` could be a block (named / default args)
- stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER)) match {
- case (presuper, supercall :: rest) =>
- stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER))
- treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr)
- case (Nil, Nil) =>
- assert(clazz eq AnyValClass, clazz)
- // AnyVal constructor - have to provide a real body so the
- // jvm doesn't throw a VerifyError. But we can't add the
- // body until now, because the typer knows that Any has no
- // constructor and won't accept a call to super.init.
- val superCall = Apply(Select(Super(This(tpnme.EMPTY), tpnme.EMPTY), nme.CONSTRUCTOR), Nil)
- Block(List(superCall), Literal(Constant()))
- }
+ val (presuper, supercall :: rest) = stats span (t => t.hasSymbolWhich(_ hasFlag PRESUPER))
+ treeCopy.Block(tree, presuper ::: (supercall :: mixinConstructorCalls ::: rest), expr)
}
}
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 59437dc036..4bb2387439 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1787,11 +1787,10 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
transformedOrTyped(ddef.rhs, EXPRmode, tpt1.tpe)
}
- if (meth.isPrimaryConstructor && meth.isClassConstructor && !isPastTyper && !reporter.hasErrors) {
+ if (meth.isPrimaryConstructor && meth.isClassConstructor && !isPastTyper && !reporter.hasErrors && !meth.owner.isSubClass(AnyValClass)) {
// At this point in AnyVal there is no supercall, which will blow up
// in computeParamAliases; there's nothing to be computed for Anyval anyway.
- if (meth.owner ne AnyValClass)
- computeParamAliases(meth.owner, vparamss1, rhs1)
+ computeParamAliases(meth.owner, vparamss1, rhs1)
}
if (tpt1.tpe.typeSymbol != NothingClass && !context.returnsSeen && rhs1.tpe.typeSymbol != NothingClass)
rhs1 = checkDead(rhs1)
diff --git a/test/files/codelib/code.jar.desired.sha1 b/test/files/codelib/code.jar.desired.sha1
index 5e7acf3b90..27326a06a8 100644
--- a/test/files/codelib/code.jar.desired.sha1
+++ b/test/files/codelib/code.jar.desired.sha1
@@ -1 +1 @@
-5880dd44ee9fedec44fed3f223842e42d8a63959 ?code.jar
+1f3f43a79512a89aa8f4e34c9288a290af8262d7 ?code.jar
diff --git a/test/files/neg/anyval-anyref-parent.check b/test/files/neg/anyval-anyref-parent.check
index b40a0f2710..be895867ff 100644
--- a/test/files/neg/anyval-anyref-parent.check
+++ b/test/files/neg/anyval-anyref-parent.check
@@ -1,4 +1,14 @@
anyval-anyref-parent.scala:5: error: Any does not have a constructor
class Bar1 extends Any // fail
^
-one error found
+anyval-anyref-parent.scala:9: error: illegal inheritance; superclass Any
+ is not a subclass of the superclass Object
+ of the mixin trait Immutable
+trait Foo4 extends Any with Immutable // fail
+ ^
+anyval-anyref-parent.scala:10: error: illegal inheritance; superclass AnyVal
+ is not a subclass of the superclass Object
+ of the mixin trait Immutable
+trait Foo5 extends AnyVal with Immutable // fail
+ ^
+three errors found
diff --git a/test/files/neg/anyval-anyref-parent.scala b/test/files/neg/anyval-anyref-parent.scala
index b7bb122ea8..08568487a9 100644
--- a/test/files/neg/anyval-anyref-parent.scala
+++ b/test/files/neg/anyval-anyref-parent.scala
@@ -5,3 +5,7 @@ trait Foo3 extends AnyRef
class Bar1 extends Any // fail
@inline class Bar2 extends AnyVal
class Bar3 extends AnyRef
+
+trait Foo4 extends Any with Immutable // fail
+trait Foo5 extends AnyVal with Immutable // fail
+trait Foo6 extends AnyRef with Immutable
diff --git a/test/files/neg/anyval-children-2.check b/test/files/neg/anyval-children-2.check
deleted file mode 100644
index cb327faeeb..0000000000
--- a/test/files/neg/anyval-children-2.check
+++ /dev/null
@@ -1,4 +0,0 @@
-anyval-children-2.scala:1: error: Only @inline classes (not traits) are allowed to extend AnyVal
-@inline trait NotOkDingus1 extends AnyVal // fail
- ^
-one error found
diff --git a/test/files/neg/anyval-children-2.scala b/test/files/neg/anyval-children-2.scala
deleted file mode 100644
index 4034eb22dd..0000000000
--- a/test/files/neg/anyval-children-2.scala
+++ /dev/null
@@ -1 +0,0 @@
-@inline trait NotOkDingus1 extends AnyVal // fail
diff --git a/test/files/neg/anyval-children.check b/test/files/neg/anyval-children.check
deleted file mode 100644
index 769f990210..0000000000
--- a/test/files/neg/anyval-children.check
+++ /dev/null
@@ -1,23 +0,0 @@
-anyval-children.scala:3: error: class AnyVal needs to be a trait to be mixed in
-@inline class NotOkDingus2 extends Immutable with AnyVal // fail
- ^
-anyval-children.scala:7: error: Bippy does not have a constructor
-class NotOkBippy1 extends Bippy // fail
- ^
-anyval-children.scala:9: error: illegal inheritance; superclass Bippy
- is not a subclass of the superclass Object
- of the mixin trait Immutable
-class NotOkBippy2 extends Bippy with Immutable //fail
- ^
-anyval-children.scala:9: error: Bippy does not have a constructor
-class NotOkBippy2 extends Bippy with Immutable //fail
- ^
-anyval-children.scala:11: error: illegal inheritance; superclass Bippy
- is not a subclass of the superclass Object
- of the mixin trait Immutable
-@inline class NotOkBippy3 extends Bippy with Immutable //fail
- ^
-anyval-children.scala:11: error: Bippy does not have a constructor
-@inline class NotOkBippy3 extends Bippy with Immutable //fail
- ^
-6 errors found
diff --git a/test/files/neg/anyval-children.scala b/test/files/neg/anyval-children.scala
deleted file mode 100644
index 5a6109f786..0000000000
--- a/test/files/neg/anyval-children.scala
+++ /dev/null
@@ -1,14 +0,0 @@
-class Bippy extends AnyVal // fail
-
-@inline class NotOkDingus2 extends Immutable with AnyVal // fail
-
-@inline object NotOkDingus3 extends AnyVal // fail
-
-class NotOkBippy1 extends Bippy // fail
-
-class NotOkBippy2 extends Bippy with Immutable //fail
-
-@inline class NotOkBippy3 extends Bippy with Immutable //fail
-
-
-@inline class OkBippy extends AnyVal // ok
diff --git a/test/files/scalap/caseClass/result.test b/test/files/scalap/caseClass/result.test
index 8e3255859f..7dfe3a0356 100644
--- a/test/files/scalap/caseClass/result.test
+++ b/test/files/scalap/caseClass/result.test
@@ -1,4 +1,4 @@
-case class CaseClass[A <: scala.Seq[scala.Int]](i : A, s : scala.Predef.String) extends java.lang.Object with scala.Product with scala.Serializable {
+case class CaseClass[A <: scala.Seq[scala.Int]](i : A, s : scala.Predef.String) extends scala.AnyRef with scala.Product with scala.Serializable {
val i : A = { /* compiled code */ }
val s : scala.Predef.String = { /* compiled code */ }
def foo : scala.Int = { /* compiled code */ }
diff --git a/test/files/scalap/caseObject/result.test b/test/files/scalap/caseObject/result.test
index 9c66c6ebb1..867a4b2162 100644
--- a/test/files/scalap/caseObject/result.test
+++ b/test/files/scalap/caseObject/result.test
@@ -1,4 +1,4 @@
-case object CaseObject extends java.lang.Object with scala.Product with scala.Serializable {
+case object CaseObject extends scala.AnyRef with scala.Product with scala.Serializable {
def bar : scala.Int = { /* compiled code */ }
override def productPrefix : java.lang.String = { /* compiled code */ }
def productArity : scala.Int = { /* compiled code */ }