Skip to content

Commit 7af35bd

Browse files
committed
Cook raw types in Java sources
This means we can drop the special treatment of EtxExpansion for Java classes in TypeComparer.
1 parent 6614628 commit 7af35bd

File tree

3 files changed

+15
-20
lines changed

3 files changed

+15
-20
lines changed

compiler/src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -602,14 +602,8 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
602602
finally comparedTypeLambdas = saved
603603
case _ =>
604604
val tparams1 = tp1.typeParams
605-
if (tparams1.nonEmpty)
606-
return recur(tp1.EtaExpand(tparams1), tp2) || fourthTry
607-
tp2 match {
608-
case EtaExpansion(tycon2) if tycon2.symbol.isClass && tycon2.symbol.is(JavaDefined) =>
609-
return recur(tp1, tycon2)
610-
case _ =>
611-
}
612-
fourthTry
605+
tparams1.nonEmpty && recur(tp1.EtaExpand(tparams1), tp2)
606+
|| fourthTry
613607
}
614608
compareTypeLambda
615609
case OrType(tp21, tp22) =>
@@ -772,14 +766,9 @@ class TypeComparer(initctx: Context) extends ConstraintHandling[AbsentContext] w
772766
case tp1: RecType =>
773767
isNewSubType(tp1.parent)
774768
case tp1: HKTypeLambda =>
775-
def compareHKLambda = tp1 match {
776-
case EtaExpansion(tycon1) if tycon1.symbol.isClass && tycon1.symbol.is(JavaDefined) =>
777-
recur(tycon1, tp2)
778-
case _ => tp2 match {
779-
case tp2: HKTypeLambda => false // this case was covered in thirdTry
780-
case _ => tp2.typeParams.hasSameLengthAs(tp1.paramRefs) && isSubType(tp1.resultType, tp2.appliedTo(tp1.paramRefs))
781-
}
782-
}
769+
def compareHKLambda = tp2 match
770+
case tp2: HKTypeLambda => false // this case was covered in thirdTry
771+
case _ => tp2.typeParams.hasSameLengthAs(tp1.paramRefs) && isSubType(tp1.resultType, tp2.appliedTo(tp1.paramRefs))
783772
compareHKLambda
784773
case AndType(tp11, tp12) =>
785774
val tp2a = tp2.dealiasKeepRefiningAnnots

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ object ClassfileParser {
3333
/** Replace raw types with wildcard applications */
3434
def cook(implicit ctx: Context): TypeMap = new TypeMap {
3535
def apply(tp: Type): Type = tp match {
36-
case tp: TypeRef if tp.symbol.typeParams.nonEmpty =>
37-
AppliedType(tp, tp.symbol.typeParams.map(Function.const(TypeBounds.empty)))
36+
case tp: TypeRef if tp.typeParams.nonEmpty =>
37+
AppliedType(tp, tp.typeParams.map(Function.const(TypeBounds.empty)))
3838
case tp @ AppliedType(tycon, args) =>
3939
// disregard tycon itself, but map over it to visit the prefix
4040
tp.derivedAppliedType(mapOver(tycon), args.mapConserve(this))
@@ -44,6 +44,8 @@ object ClassfileParser {
4444
case tp @ TempClassInfoType(parents, _, _) =>
4545
val parents1 = parents.mapConserve(this)
4646
if (parents eq parents1) tp else tp.copy(parentTypes = parents1)
47+
case tp: ClassInfo =>
48+
tp.derivedClassInfo(classParents = tp.classParents.mapConserve(this))
4749
case _ =>
4850
mapOver(tp)
4951
}

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import core._
66
import ast._
77
import Trees._, StdNames._, Scopes._, Denotations._, Comments._
88
import Contexts._, Symbols._, Types._, SymDenotations._, Names._, NameOps._, Flags._, Decorators._
9+
import classfile.ClassfileParser
910
import NameKinds.DefaultGetterName
1011
import TypeApplications.TypeParamInfo
1112
import ast.desugar, ast.desugar._
@@ -919,6 +920,9 @@ class Namer { typer: Typer =>
919920
end if
920921
}
921922

923+
protected def cookIfJava(tp: Type)(using Context): Type =
924+
if ctx.compilationUnit.isJava then ClassfileParser.cook.apply(tp) else tp
925+
922926
/** Intentionally left without `implicit ctx` parameter. We need
923927
* to pick up the context at the point where the completer was created.
924928
*/
@@ -929,7 +933,7 @@ class Namer { typer: Typer =>
929933
denot.info = typeSig(sym)
930934
invalidateIfClashingSynthetic(denot)
931935
Checking.checkWellFormed(sym)
932-
denot.info = avoidPrivateLeaks(sym)
936+
denot.info = cookIfJava(avoidPrivateLeaks(sym))
933937
}
934938
}
935939

@@ -1288,7 +1292,7 @@ class Namer { typer: Typer =>
12881292

12891293
Checking.checkWellFormed(cls)
12901294
if (isDerivedValueClass(cls)) cls.setFlag(Final)
1291-
cls.info = avoidPrivateLeaks(cls)
1295+
cls.info = cookIfJava(avoidPrivateLeaks(cls))
12921296
cls.baseClasses.foreach(_.invalidateBaseTypeCache()) // we might have looked before and found nothing
12931297
cls.setNoInitsFlags(parentsKind(parents), untpd.bodyKind(rest))
12941298
if (cls.isNoInitsClass) cls.primaryConstructor.setFlag(StableRealizable)

0 commit comments

Comments
 (0)