Skip to content

Commit 8d0312f

Browse files
committed
Avoid creating AndTypes with Any
This reduces the number of implicit scopes we cache.
1 parent 5c2a19b commit 8d0312f

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2145,7 +2145,12 @@ object Types {
21452145
unique(new CachedAndType(tp1, tp2))
21462146
}
21472147
def make(tp1: Type, tp2: Type)(implicit ctx: Context): Type =
2148-
if (tp1 eq tp2) tp1 else apply(tp1, tp2)
2148+
if ((tp1 eq tp2) || (tp2 eq defn.AnyType))
2149+
tp1
2150+
else if (tp1 eq defn.AnyType)
2151+
tp2
2152+
else
2153+
apply(tp1, tp2)
21492154
}
21502155

21512156
abstract case class OrType(tp1: Type, tp2: Type) extends CachedGroundType with AndOrType {

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ trait ImplicitRunInfo { self: RunInfo =>
287287
case tp: TypeRef if tp.symbol.isAbstractOrAliasType =>
288288
val pre = tp.prefix
289289
def joinClass(tp: Type, cls: ClassSymbol) =
290-
AndType(tp, cls.typeRef.asSeenFrom(pre, cls.owner))
290+
AndType.make(tp, cls.typeRef.asSeenFrom(pre, cls.owner))
291291
val lead = if (tp.prefix eq NoPrefix) defn.AnyType else apply(tp.prefix)
292292
(lead /: tp.classSymbols)(joinClass)
293293
case tp: TypeVar =>

0 commit comments

Comments
 (0)