diff options
author | odersky <odersky@gmail.com> | 2012-07-30 05:41:48 -0700 |
---|---|---|
committer | odersky <odersky@gmail.com> | 2012-07-30 05:41:48 -0700 |
commit | 8e62dc93e2756db569fa00b50a80deba0fc1eece (patch) | |
tree | f601617de25fea6cd847822397eabf53126ba915 /src | |
parent | e77dbfc774b929df78aa408e86bce7eeec1271ee (diff) | |
parent | daf0953c1f5d76b468a75911f3f22162d631415c (diff) | |
download | scala-8e62dc93e2756db569fa00b50a80deba0fc1eece.tar.gz scala-8e62dc93e2756db569fa00b50a80deba0fc1eece.tar.bz2 scala-8e62dc93e2756db569fa00b50a80deba0fc1eece.zip |
Merge pull request #1013 from odersky/ticket/5878
Closes SI-5878
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala index 5f66cadbc9..e937589f54 100644 --- a/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala +++ b/src/compiler/scala/tools/nsc/transform/ExtensionMethods.scala @@ -78,13 +78,13 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { } /** This method removes the `$this` argument from the parameter list a method. - * + * * A method may be a `PolyType`, in which case we tear out the `$this` and the class * type params from its nested `MethodType`. * It may be a `MethodType`, either with a curried parameter list in which the first argument * is a `$this` - we just return the rest of the list. * This means that the corresponding symbol was generated during `extmethods`. - * + * * It may also be a `MethodType` in which the `$this` does not appear in a curried parameter list. * The curried lists disappear during `uncurry`, and the methods may be duplicated afterwards, * for instance, during `specialize`. @@ -105,6 +105,14 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { private val extensionDefs = mutable.Map[Symbol, mutable.ListBuffer[Tree]]() + def checkNonCyclic(pos: Position, seen: Set[Symbol], clazz: Symbol): Unit = + if (seen contains clazz) + unit.error(pos, "value class may not unbox to itself") + else { + val unboxed = erasure.underlyingOfValueClass(clazz).typeSymbol + if (unboxed.isDerivedValueClass) checkNonCyclic(pos, seen + clazz, unboxed) + } + def extensionMethInfo(extensionMeth: Symbol, origInfo: Type, clazz: Symbol): Type = { var newTypeParams = cloneSymbolsAtOwner(clazz.typeParams, extensionMeth) val thisParamType = appliedType(clazz.typeConstructor, newTypeParams map (_.tpeHK)) @@ -129,6 +137,7 @@ abstract class ExtensionMethods extends Transform with TypingTransformers { tree match { case Template(_, _, _) => if (currentOwner.isDerivedValueClass) { + checkNonCyclic(currentOwner.pos, Set(), currentOwner) extensionDefs(currentOwner.companionModule) = new mutable.ListBuffer[Tree] currentOwner.primaryConstructor.makeNotPrivate(NoSymbol) super.transform(tree) |