aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/core/SymDenotations.scala42
-rw-r--r--src/dotty/tools/dotc/core/TypeApplications.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeComparer.scala2
-rw-r--r--src/dotty/tools/dotc/core/TypeOps.scala4
-rw-r--r--src/dotty/tools/dotc/core/Types.scala8
-rw-r--r--src/dotty/tools/dotc/core/pickling/UnPickler.scala2
-rw-r--r--src/dotty/tools/dotc/core/transform/Erasure.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala2
-rw-r--r--tests/pos/structural.scala21
9 files changed, 54 insertions, 31 deletions
diff --git a/src/dotty/tools/dotc/core/SymDenotations.scala b/src/dotty/tools/dotc/core/SymDenotations.scala
index 225fdbcc0..ebe52d522 100644
--- a/src/dotty/tools/dotc/core/SymDenotations.scala
+++ b/src/dotty/tools/dotc/core/SymDenotations.scala
@@ -449,7 +449,7 @@ object SymDenotations {
| ${owner.showLocated} where target is defined""".stripMargin)
else if (
!( isType // allow accesses to types from arbitrary subclasses fixes #4737
- || pre.baseType(cls).exists
+ || pre.baseTypeRef(cls).exists // ??? why not use derivesFrom ???
|| isConstructor
|| (owner is ModuleClass) // don't perform this check for static members
))
@@ -850,12 +850,12 @@ object SymDenotations {
private[this] var myBaseClasses: List[ClassSymbol] = null
private[this] var mySuperClassBits: BitSet = null
- /** Invalidate baseTypeCache and superClassBits on new run */
+ /** Invalidate baseTypeRefCache and superClassBits on new run */
private def checkBasesUpToDate()(implicit ctx: Context) =
- if (baseTypeValid != ctx.runId) {
- baseTypeCache = new java.util.HashMap[CachedType, Type]
+ if (baseTypeRefValid != ctx.runId) {
+ baseTypeRefCache = new java.util.HashMap[CachedType, Type]
mySuperClassBits = null
- baseTypeValid = ctx.runId
+ baseTypeRefValid = ctx.runId
}
private def computeBases(implicit ctx: Context): Unit = {
@@ -1065,18 +1065,18 @@ object SymDenotations {
raw.filterExcluded(excluded).asSeenFrom(pre).toDenot(pre)
}
- private[this] var baseTypeCache: java.util.HashMap[CachedType, Type] = null
- private[this] var baseTypeValid: RunId = NoRunId
+ private[this] var baseTypeRefCache: java.util.HashMap[CachedType, Type] = null
+ private[this] var baseTypeRefValid: RunId = NoRunId
- /** Compute tp.baseType(this) */
- final def baseTypeOf(tp: Type)(implicit ctx: Context): Type = {
+ /** Compute tp.baseTypeRef(this) */
+ final def baseTypeRefOf(tp: Type)(implicit ctx: Context): Type = {
def foldGlb(bt: Type, ps: List[Type]): Type = ps match {
- case p :: ps1 => foldGlb(bt & baseTypeOf(p), ps1)
+ case p :: ps1 => foldGlb(bt & baseTypeRefOf(p), ps1)
case _ => bt
}
- def computeBaseTypeOf(tp: Type): Type = {
+ def computeBaseTypeRefOf(tp: Type): Type = {
Stats.record("computeBaseTypeOf")
if (symbol.isStatic && tp.derivesFrom(symbol))
symbol.typeRef
@@ -1090,34 +1090,34 @@ object SymDenotations {
if (cdenot.superClassBits contains symbol.superId) foldGlb(NoType, tp.parents)
else NoType
case _ =>
- baseTypeOf(tp.underlying)
+ baseTypeRefOf(tp.underlying)
}
case tp: TypeProxy =>
- baseTypeOf(tp.underlying)
+ baseTypeRefOf(tp.underlying)
case AndType(tp1, tp2) =>
- baseTypeOf(tp1) & baseTypeOf(tp2)
+ baseTypeRefOf(tp1) & baseTypeRefOf(tp2)
case OrType(tp1, tp2) =>
- baseTypeOf(tp1) | baseTypeOf(tp2)
+ baseTypeRefOf(tp1) | baseTypeRefOf(tp2)
case _ =>
NoType
}
}
- /*>|>*/ ctx.debugTraceIndented(s"$tp.baseType($this)") /*<|<*/ {
+ /*>|>*/ ctx.debugTraceIndented(s"$tp.baseTypeRef($this)") /*<|<*/ {
tp match {
case tp: CachedType =>
checkBasesUpToDate()
- var basetp = baseTypeCache get tp
+ var basetp = baseTypeRefCache get tp
if (basetp == null) {
- baseTypeCache.put(tp, NoPrefix)
- basetp = computeBaseTypeOf(tp)
- baseTypeCache.put(tp, basetp)
+ baseTypeRefCache.put(tp, NoPrefix)
+ basetp = computeBaseTypeRefOf(tp)
+ baseTypeRefCache.put(tp, basetp)
} else if (basetp == NoPrefix) {
throw new CyclicReference(this)
}
basetp
case _ =>
- computeBaseTypeOf(tp)
+ computeBaseTypeRefOf(tp)
}
}
}
diff --git a/src/dotty/tools/dotc/core/TypeApplications.scala b/src/dotty/tools/dotc/core/TypeApplications.scala
index 5659ec9c6..e854e672f 100644
--- a/src/dotty/tools/dotc/core/TypeApplications.scala
+++ b/src/dotty/tools/dotc/core/TypeApplications.scala
@@ -152,7 +152,7 @@ class TypeApplications(val self: Type) extends AnyVal {
/** The base type including all type arguments of this type */
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type =
- self.baseType(base).appliedTo(baseTypeArgs(base))
+ self.baseTypeRef(base).appliedTo(baseTypeArgs(base))
/** Translate a type of the form From[T] to To[T], keep other types as they are.
* `from` and `to` must be static classes, both with one type parameter, and the same variance.
diff --git a/src/dotty/tools/dotc/core/TypeComparer.scala b/src/dotty/tools/dotc/core/TypeComparer.scala
index f9d848c55..0af6ebf97 100644
--- a/src/dotty/tools/dotc/core/TypeComparer.scala
+++ b/src/dotty/tools/dotc/core/TypeComparer.scala
@@ -405,7 +405,7 @@ class TypeComparer(initctx: Context) extends DotClass {
case _ =>
val cls2 = tp2.symbol
if (cls2.isClass) {
- val base = tp1.baseType(cls2)
+ val base = tp1.baseTypeRef(cls2)
if (base.exists && (base ne tp1)) return isSubType(base, tp2)
if ( cls2 == defn.SingletonClass && tp1.isStable
|| cls2 == defn.NotNullClass && tp1.isNotNull
diff --git a/src/dotty/tools/dotc/core/TypeOps.scala b/src/dotty/tools/dotc/core/TypeOps.scala
index 272e93dd3..ca69ab615 100644
--- a/src/dotty/tools/dotc/core/TypeOps.scala
+++ b/src/dotty/tools/dotc/core/TypeOps.scala
@@ -12,13 +12,13 @@ trait TypeOps { this: Context =>
def toPrefix(pre: Type, cls: Symbol, thiscls: ClassSymbol): Type = /*>|>*/ ctx.debugTraceIndented(s"toPrefix($pre, $cls, $thiscls)") /*<|<*/ {
if ((pre eq NoType) || (pre eq NoPrefix) || (cls is PackageClass))
tp
- else if (thiscls.derivesFrom(cls) && pre.baseType(thiscls).exists)
+ else if (thiscls.derivesFrom(cls) && pre.baseTypeRef(thiscls).exists)
pre match {
case SuperType(thispre, _) => thispre
case _ => pre
}
else
- toPrefix(pre.baseType(cls).normalizedPrefix, cls.owner, thiscls)
+ toPrefix(pre.baseTypeRef(cls).normalizedPrefix, cls.owner, thiscls)
}
/*>|>*/ ctx.conditionalTraceIndented(TypeOps.track , s"asSeen ${tp.show} from (${pre.show}, ${cls.show})", show = true) /*<|<*/ { // !!! DEBUG
diff --git a/src/dotty/tools/dotc/core/Types.scala b/src/dotty/tools/dotc/core/Types.scala
index 1aaa85481..bc8d7dfd2 100644
--- a/src/dotty/tools/dotc/core/Types.scala
+++ b/src/dotty/tools/dotc/core/Types.scala
@@ -495,10 +495,12 @@ object Types {
this, that, alwaysMatchSimple = !ctx.phase.erasedTypes)
}
- /** The basetype of this type with given class symbol */
- final def baseType(base: Symbol)(implicit ctx: Context): Type = /*ctx.traceIndented(s"$this baseType $base")*/ /*>|>*/ track("baseType") /*<|<*/ {
+ /** The basetype TypeRef of this type with given class symbol,
+ * but without including any type arguments
+ */
+ final def baseTypeRef(base: Symbol)(implicit ctx: Context): Type = /*ctx.traceIndented(s"$this baseTypeRef $base")*/ /*>|>*/ track("baseTypeRef") /*<|<*/ {
base.denot match {
- case classd: ClassDenotation => classd.baseTypeOf(this)//widen.dealias)
+ case classd: ClassDenotation => classd.baseTypeRefOf(this)//widen.dealias)
case _ => NoType
}
}
diff --git a/src/dotty/tools/dotc/core/pickling/UnPickler.scala b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
index 84b300a2a..c48e71052 100644
--- a/src/dotty/tools/dotc/core/pickling/UnPickler.scala
+++ b/src/dotty/tools/dotc/core/pickling/UnPickler.scala
@@ -631,7 +631,7 @@ class UnPickler(bytes: Array[Byte], classRoot: ClassDenotation, moduleClassRoot:
if (sym.owner != cls) {
val overriding = cls.decls.lookup(sym.name)
if (overriding.exists && overriding != sym) {
- val base = pre.baseType(sym.owner)
+ val base = pre.baseTypeWithArgs(sym.owner)
assert(base.exists)
pre = SuperType(pre, base)
}
diff --git a/src/dotty/tools/dotc/core/transform/Erasure.scala b/src/dotty/tools/dotc/core/transform/Erasure.scala
index 34f339d9a..eaeb3c8e7 100644
--- a/src/dotty/tools/dotc/core/transform/Erasure.scala
+++ b/src/dotty/tools/dotc/core/transform/Erasure.scala
@@ -51,7 +51,7 @@ object Erasure {
case AndType(tp1, tp2) =>
erasure(tp1)
case OrType(tp1, tp2) =>
- erasure(tp.baseType(lubClass(tp1, tp2)))
+ erasure(tp.baseTypeRef(lubClass(tp1, tp2)))
case tp: MethodType =>
tp.derivedMethodType(
tp.paramNames, tp.paramTypes.mapConserve(erasure), resultErasure(tp.resultType))
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 15dd0e9ad..4b43aa8b7 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -222,7 +222,7 @@ trait Applications extends Compatibility { self: Typer =>
val pre =
if (meth.isClassConstructor) {
// default getters for class constructors are found in the companion object
- mpre.baseType(cls) match {
+ mpre.baseTypeRef(cls) match {
case tp: TypeRef => ref(tp.prefix, cls.companionModule)
case _ => NoType
}
diff --git a/tests/pos/structural.scala b/tests/pos/structural.scala
new file mode 100644
index 000000000..8afa49ed0
--- /dev/null
+++ b/tests/pos/structural.scala
@@ -0,0 +1,21 @@
+object test123 {
+ type A = { def a: Int }
+ def f(a: A): A = a
+}
+
+object structural2 {
+ type A = { def a: Int }
+
+ type B = {
+ def b: Int
+ }
+
+ type AB = A & B
+
+ def f(ab: AB): AB = ab
+
+ f(new {
+ def a = 43
+ def b = 42
+ })
+} \ No newline at end of file