Skip to content

Commit 07939c9

Browse files
oderskygzm0
authored andcommitted
Fix of t1279a: baseTypeWithArgs
baseTypeWithArgs now also keeps track of refinements in the subtypes. Without that, the approximated lub in t1279a is too coarse and the program fails to typecheck.
1 parent 7e1343e commit 07939c9

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

src/dotty/tools/dotc/core/TypeApplications.scala

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import util.common._
1010
import Names._
1111
import Flags._
1212
import util.Positions.Position
13+
import config.Printers._
1314
import collection.mutable
1415

1516
object TypeApplications {
@@ -195,13 +196,32 @@ class TypeApplications(val self: Type) extends AnyVal {
195196
NoType
196197
}
197198

198-
/** The base type including all type arguments of this type.
199+
/** The base type including all type arguments and applicable refinements
200+
* of this type. Refinements are applicable if they refine a member of
201+
* the parent type which furthermore is not a name-mangled type parameter.
199202
* Existential types in arguments are returned as TypeBounds instances.
200203
*/
201-
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = self.dealias match {
202-
case AndType(tp1, tp2) => tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base)
203-
case OrType(tp1, tp2) => tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base)
204-
case _ => self.baseTypeRef(base).appliedTo(baseArgInfos(base))
204+
final def baseTypeWithArgs(base: Symbol)(implicit ctx: Context): Type = ctx.traceIndented(s"btwa ${self.show} wrt $base", core, show = true) {
205+
def default = self.baseTypeRef(base).appliedTo(baseArgInfos(base))
206+
self match {
207+
case tp: TypeRef =>
208+
tp.info match {
209+
case TypeBounds(_, hi) => hi.baseTypeWithArgs(base)
210+
case _ => default
211+
}
212+
case tp @ RefinedType(parent, name) if !tp.member(name).symbol.is(ExpandedTypeParam) =>
213+
val pbase = parent.baseTypeWithArgs(base)
214+
if (pbase.member(name).exists) RefinedType(pbase, name, tp.refinedInfo)
215+
else pbase
216+
case tp: TermRef =>
217+
tp.underlying.baseTypeWithArgs(base)
218+
case AndType(tp1, tp2) =>
219+
tp1.baseTypeWithArgs(base) & tp2.baseTypeWithArgs(base)
220+
case OrType(tp1, tp2) =>
221+
tp1.baseTypeWithArgs(base) | tp2.baseTypeWithArgs(base)
222+
case _ =>
223+
default
224+
}
205225
}
206226

207227
/** Translate a type of the form From[T] to To[T], keep other types as they are.
File renamed without changes.

0 commit comments

Comments
 (0)