summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2012-02-19 18:02:44 +0100
committerMartin Odersky <odersky@gmail.com>2012-02-19 18:03:19 +0100
commit64aaef72504b46b9d40359eb0476ad8416f36023 (patch)
treecb41068323ee789847e287a9caf6695856580f16 /src
parent8cc7de74d35b437b7126d02a6219796b5872ac14 (diff)
downloadscala-64aaef72504b46b9d40359eb0476ad8416f36023.tar.gz
scala-64aaef72504b46b9d40359eb0476ad8416f36023.tar.bz2
scala-64aaef72504b46b9d40359eb0476ad8416f36023.zip
Implemented super access in value classes, restrictions for value classes.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/reflect/internal/Symbols.scala2
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala15
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala18
4 files changed, 24 insertions, 14 deletions
diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala
index 89af10283b..d3641c1ee8 100644
--- a/src/compiler/scala/reflect/internal/Symbols.scala
+++ b/src/compiler/scala/reflect/internal/Symbols.scala
@@ -504,7 +504,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
!isPrimitiveValueClass
final def isMethodWithExtension =
- isMethod && owner.isInlineClass && !isParamAccessor && !isConstructor
+ isMethod && owner.isInlineClass && !isParamAccessor && !isConstructor && !hasFlag(SUPERACCESSOR)
final def isAnonymousClass = isClass && (name containsName tpnme.ANON_CLASS_NAME)
final def isAnonymousFunction = isSynthetic && (name containsName tpnme.ANON_FUN_NAME)
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 3f6a0f8f73..a3529020d4 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -438,12 +438,6 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
val global: Global.this.type = Global.this
} with Analyzer
- object extensionMethods extends {
- val global: Global.this.type = Global.this
- val runsAfter = List("typer")
- val runsRightAfter = None
- } with ExtensionMethods
-
// phaseName = "superaccessors"
object superAccessors extends {
val global: Global.this.type = Global.this
@@ -451,10 +445,17 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb
val runsRightAfter = None
} with SuperAccessors
+ // phaseName = "extmethods"
+ object extensionMethods extends {
+ val global: Global.this.type = Global.this
+ val runsAfter = List("superaccessors")
+ val runsRightAfter = None
+ } with ExtensionMethods
+
// phaseName = "pickler"
object pickler extends {
val global: Global.this.type = Global.this
- val runsAfter = List("superaccessors")
+ val runsAfter = List("extmethods")
val runsRightAfter = None
} with Pickler
diff --git a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
index 0ab09b4fec..d294cc86bc 100644
--- a/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/SuperAccessors.scala
@@ -237,6 +237,9 @@ abstract class SuperAccessors extends transform.Transform with transform.TypingT
}
transformSuperSelect(tree)
+ case DefDef(mods, name, tparams, vparamss, tpt, rhs) if tree.symbol.isMethodWithExtension =>
+ treeCopy.DefDef(tree, mods, name, tparams, vparamss, tpt, withInvalidOwner(transform(rhs)))
+
case TypeApply(sel @ Select(qual, name), args) =>
mayNeedProtectedAccessor(sel, args, true)
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 008a2e1764..fde9b6f551 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -1205,13 +1205,19 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
sym == acc || acc.hasAccessorFlag && sym == acc.accessed
if (acc.accessBoundary(clazz) != RootClass)
unit.error(acc.pos, "Value class needs to have a publicly accessible val parameter")
- else
- for (stat <- body)
- if (!treeInfo.isAllowedInUniversalTrait(stat) && !isUnderlyingAcc(stat.symbol))
- unit.error(stat.pos, "This statement is not allowed in value class: "+stat)
+ if (acc.tpe.resultType.typeSymbol.isTypeParameter)
+ unit.error(acc.pos, "Type of parameter of value class may not be a type variable")
+ for (stat <- body)
+ if (!treeInfo.isAllowedInUniversalTrait(stat) && !isUnderlyingAcc(stat.symbol))
+ unit.error(stat.pos,
+ if (stat.symbol hasFlag PARAMACCESSOR) "Illegal parameter for value class"
+ else "This statement is not allowed in value class: "+stat)
case x =>
unit.error(clazz.pos, "Value class needs to have exactly one public val parameter")
}
+ for (tparam <- clazz.typeParams)
+ if (tparam hasAnnotation definitions.SpecializedClass)
+ unit.error(tparam.pos, "type parameter of value class may not be specialized")
}
def parentTypes(templ: Template): List[Tree] =
@@ -1437,10 +1443,10 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser {
_.typedTemplate(cdef.impl, parentTypes(cdef.impl))
}
val impl2 = finishMethodSynthesis(impl1, clazz, context)
- if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.firstParent.typeSymbol == AnyClass)
+ if (clazz.isTrait && clazz.info.parents.nonEmpty && clazz.info.firstParent.normalize.typeSymbol == AnyClass)
for (stat <- impl2.body)
if (!treeInfo.isAllowedInUniversalTrait(stat))
- unit.error(stat.pos, "this statement is not allowed in trait extending from class Any: "+stat)
+ unit.error(stat.pos, "this statement is not allowed in universal trait extending from class Any: "+stat)
if ((clazz != ClassfileAnnotationClass) &&
(clazz isNonBottomSubClass ClassfileAnnotationClass))
restrictionWarning(cdef.pos, unit,