aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/dotty/tools/dotc/core')
-rw-r--r--src/dotty/tools/dotc/core/Denotations.scala1
-rw-r--r--src/dotty/tools/dotc/core/NameOps.scala9
-rw-r--r--src/dotty/tools/dotc/core/Signature.scala2
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala45
-rw-r--r--src/dotty/tools/dotc/core/Symbols.scala12
-rw-r--r--src/dotty/tools/dotc/core/Types.scala9
-rw-r--r--src/dotty/tools/dotc/core/pickling/ClassfileParser.scala2
7 files changed, 70 insertions, 10 deletions
diff --git a/src/dotty/tools/dotc/core/Denotations.scala b/src/dotty/tools/dotc/core/Denotations.scala
index 264f9aa46..120f8e0f8 100644
--- a/src/dotty/tools/dotc/core/Denotations.scala
+++ b/src/dotty/tools/dotc/core/Denotations.scala
@@ -574,6 +574,7 @@ object Denotations {
/** Install this denotation to be the result of the given denotation transformer.
* This is the implementation of the same-named method in SymDenotations.
* It's placed here because it needs access to private fields of SingleDenotation.
+ * @pre Can only be called in `phase.next`.
*/
protected def installAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = {
val targetId = phase.next.id
diff --git a/src/dotty/tools/dotc/core/NameOps.scala b/src/dotty/tools/dotc/core/NameOps.scala
index 7c10bfd4d..404a0844a 100644
--- a/src/dotty/tools/dotc/core/NameOps.scala
+++ b/src/dotty/tools/dotc/core/NameOps.scala
@@ -132,6 +132,9 @@ object NameOps {
if (flags is (ModuleClass, butNot = Package)) name.asTypeName.moduleClassName.asInstanceOf[N]
else name
+ /** The superaccessor for method with given name */
+ def superName: TermName = (nme.SUPER_PREFIX ++ name).toTermName
+
/** The expanded name of `name` relative to this class `base` with given `separator`
*/
def expandedName(base: Symbol, separator: Name = nme.EXPAND_SEPARATOR)(implicit ctx: Context): N = {
@@ -255,11 +258,11 @@ object NameOps {
/** The name of an accessor for protected symbols. */
def protectedAccessorName: TermName =
- PROTECTED_PREFIX ++ name
+ PROTECTED_PREFIX ++ name.unexpandedName()
/** The name of a setter for protected symbols. Used for inherited Java fields. */
- def protectedSetterName(name: Name): TermName =
- PROTECTED_SET_PREFIX ++ name
+ def protectedSetterName: TermName =
+ PROTECTED_SET_PREFIX ++ name.unexpandedName()
def moduleVarName: TermName =
name ++ MODULE_VAR_SUFFIX
diff --git a/src/dotty/tools/dotc/core/Signature.scala b/src/dotty/tools/dotc/core/Signature.scala
index eb85fbb99..22d038d11 100644
--- a/src/dotty/tools/dotc/core/Signature.scala
+++ b/src/dotty/tools/dotc/core/Signature.scala
@@ -49,7 +49,7 @@ object Signature {
* a type different from PolyType, MethodType, or ExprType.
*/
val NotAMethod = Signature(List(), EmptyTypeName)
-
+
/** The signature of an overloaded denotation.
*/
val OverloadedSignature = Signature(List(tpnme.OVERLOADED), EmptyTypeName)
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 802762045..643237038 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -395,6 +395,14 @@ object SymDenotations {
/** Is this a user defined "def" method? Excluded are accessors. */
final def isSourceMethod(implicit ctx: Context) = this is (Method, butNot = Accessor)
+ /** This this a method in a value class that is implemented as an extension method? */
+ final def isMethodWithExtension(implicit ctx: Context) =
+ isSourceMethod &&
+ owner.isDerivedValueClass &&
+ !isConstructor &&
+ !is(SuperAccessor) &&
+ !is(Macro)
+
/** Is this a setter? */
final def isGetter(implicit ctx: Context) = (this is Accessor) && !originalName.isSetterName
@@ -447,7 +455,7 @@ object SymDenotations {
def accessWithin(boundary: Symbol) =
ctx.owner.isContainedIn(boundary) &&
(!(this is JavaDefined) || // disregard package nesting for Java
- ctx.owner.enclosingPackage == boundary.enclosingPackage)
+ ctx.owner.enclosingPackageClass == boundary.enclosingPackageClass)
/** Are we within definition of linked class of `boundary`? */
def accessWithinLinked(boundary: Symbol) = {
@@ -572,6 +580,12 @@ object SymDenotations {
NoSymbol
}
+ /** The field accessed by this getter or setter */
+ def accessedField(implicit ctx: Context): Symbol = {
+ val fieldName = if (isSetter) name.asTermName.setterToGetter else name
+ owner.info.decl(fieldName).suchThat(d => !(d is Method)).symbol
+ }
+
/** The chain of owners of this denotation, starting with the denoting symbol itself */
final def ownersIterator(implicit ctx: Context) = new Iterator[Symbol] {
private[this] var current = symbol
@@ -624,8 +638,8 @@ object SymDenotations {
}
/** The package class containing this denotation */
- final def enclosingPackage(implicit ctx: Context): Symbol =
- if (this is PackageClass) symbol else owner.enclosingPackage
+ final def enclosingPackageClass(implicit ctx: Context): Symbol =
+ if (this is PackageClass) symbol else owner.enclosingPackageClass
/** The module object with the same (term-) name as this class or module class,
* and which is also defined in the same scope and compilation unit.
@@ -747,7 +761,6 @@ object SymDenotations {
loop(base.info.baseClasses.dropWhile(owner != _).tail)
}
-
/** A a member of class `base` is incomplete if
* (1) it is declared deferred or
* (2) it is abstract override and its super symbol in `base` is
@@ -895,6 +908,15 @@ object SymDenotations {
case _ => Nil
}
+ /** The symbol of the superclass, NoSymbol if no superclass exists */
+ def superClass(implicit ctx: Context): Symbol = classParents match {
+ case parent :: _ =>
+ val cls = parent.classSymbol
+ if (cls is Trait) NoSymbol else cls
+ case _ =>
+ NoSymbol
+ }
+
/** The denotation is fully completed: all attributes are fully defined.
* ClassDenotations compiled from source are first completed, then fully completed.
* @see Namer#ClassCompleter
@@ -1292,6 +1314,21 @@ object SymDenotations {
def underlyingOfValueClass: Type = ???
def valueClassUnbox: Symbol = ???
+
+ /** If this class has the same `decls` scope reference in `phase` and
+ * `phase.next`, install a new denotation with a cloned scope in `phase.next`.
+ * @pre Can only be called in `phase.next`.
+ */
+ def ensureFreshScopeAfter(phase: DenotTransformer)(implicit ctx: Context): Unit = {
+ assert(ctx.phaseId == phase.next.id)
+ val prevCtx = ctx.withPhase(phase)
+ val ClassInfo(pre, _, ps, decls, selfInfo) = classInfo
+ if (classInfo(prevCtx).decls eq decls) {
+ copySymDenotation(
+ info = ClassInfo(pre, classSymbol, ps, decls.cloneScope, selfInfo),
+ initFlags = this.flags &~ Frozen).installAfter(phase)
+ }
+ }
}
/** The denotation of a package class.
diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala
index 26553ddff..cfd5bdf23 100644
--- a/src/dotty/tools/dotc/core/Symbols.scala
+++ b/src/dotty/tools/dotc/core/Symbols.scala
@@ -16,6 +16,7 @@ import printing.Printer
import Types._
import Annotations._
import util.Positions._
+import DenotTransformers._
import StdNames._
import NameOps._
import ast.tpd.{TreeTypeMap, Tree}
@@ -372,6 +373,17 @@ object Symbols {
this
}
+ /** Enter this symbol in its class owner after given `phase`. Create a fresh
+ * denotation for its owner class if the class has not yet already one
+ * that starts being valid after `phase`.
+ * @pre Symbol is a class member
+ */
+ def enteredAfter(phase: DenotTransformer)(implicit ctx: Context): this.type = {
+ val nextCtx = ctx.withPhase(phase.next)
+ this.owner.asClass.ensureFreshScopeAfter(phase)(nextCtx)
+ entered(nextCtx)
+ }
+
/** This symbol, if it exists, otherwise the result of evaluating `that` */
def orElse(that: => Symbol)(implicit ctx: Context) =
if (this.exists) this else that
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index dad88bc60..a92b252b5 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -1609,10 +1609,15 @@ object Types {
protected def computeSignature(implicit ctx: Context): Signature
- protected def resultSignature(implicit ctx: Context) = resultType match {
+ protected def resultSignature(implicit ctx: Context) = try resultType match {
case rtp: SignedType => rtp.signature
case tp => Signature(tp, isJava = false)
}
+ catch {
+ case ex: AssertionError =>
+ println(i"failure while taking result signture of $resultType")
+ throw ex
+ }
final override def signature(implicit ctx: Context): Signature = {
if (ctx.runId != mySignatureRunId) {
@@ -1717,6 +1722,8 @@ object Types {
def apply(paramNames: List[TermName], paramTypes: List[Type])(resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType
def apply(paramNames: List[TermName], paramTypes: List[Type], resultType: Type)(implicit ctx: Context): MethodType =
apply(paramNames, paramTypes)(_ => resultType)
+ def apply(paramTypes: List[Type])(resultTypeExp: MethodType => Type)(implicit ctx: Context): MethodType =
+ apply(nme.syntheticParamNames(paramTypes.length), paramTypes)(resultTypeExp)
def apply(paramTypes: List[Type], resultType: Type)(implicit ctx: Context): MethodType =
apply(nme.syntheticParamNames(paramTypes.length), paramTypes, resultType)
def fromSymbols(params: List[Symbol], resultType: Type)(implicit ctx: Context) = {
diff --git a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
index 0ed301732..0f0747597 100644
--- a/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
+++ b/src/dotty/tools/dotc/core/pickling/ClassfileParser.scala
@@ -752,7 +752,7 @@ class ClassfileParser(
private def setPrivateWithin(denot: SymDenotation, jflags: Int)(implicit ctx: Context): Unit = {
if ((jflags & (JAVA_ACC_PRIVATE | JAVA_ACC_PUBLIC)) == 0)
- denot.privateWithin = denot.enclosingPackage
+ denot.privateWithin = denot.enclosingPackageClass
}
private def isPrivate(flags: Int) = (flags & JAVA_ACC_PRIVATE) != 0