Skip to content

Commit 09bb2c8

Browse files
committed
Apply suggestions from code review
1 parent 72987de commit 09bb2c8

File tree

7 files changed

+14
-22
lines changed

7 files changed

+14
-22
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,11 +2117,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
21172117
case nil =>
21182118
formals2.isEmpty
21192119
}
2120-
// Check if methods are erased, then the erased parameters match
2121-
val erasedValid =
2122-
if tp1.hasErasedParams && tp2.hasErasedParams then
2123-
tp1.erasedParams == tp2.erasedParams
2124-
else !tp1.hasErasedParams && !tp2.hasErasedParams
2120+
// If methods have erased parameters, then the erased parameters must match
2121+
val erasedValid = (!tp1.hasErasedParams && !tp2.hasErasedParams) || (tp1.erasedParams == tp2.erasedParams)
21252122

21262123
erasedValid && loop(tp1.paramInfos, tp2.paramInfos)
21272124
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1473,7 +1473,7 @@ object Types {
14731473

14741474
/** Dealias, and if result is a dependent function type, drop the `apply` refinement. */
14751475
final def dropDependentRefinement(using Context): Type = dealias match {
1476-
case RefinedType(parent, nme.apply, mt) if !defn.isErasedFunctionType(parent) => parent
1476+
case RefinedType(parent, nme.apply, mt) if defn.isNonRefinedFunction(parent) => parent
14771477
case tp => tp
14781478
}
14791479

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3253,7 +3253,6 @@ object Parsers {
32533253
val firstParamMod =
32543254
var mods = EmptyModifiers
32553255
if isErased then mods = addModifier(mods)
3256-
// if in.name == nme.inline then mods = addModifier(mods)
32573256
mods
32583257
if givenOnly && !impliedMods.is(Given) then
32593258
syntaxError(em"`using` expected")

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -827,12 +827,10 @@ object Erasure {
827827
val Apply(fun, args) = tree
828828
val origFun = fun.asInstanceOf[tpd.Tree]
829829
val origFunType = origFun.tpe.widen(using preErasureCtx)
830-
val erasedCompanion = if origFunType.hasErasedParams then
831-
Some(origFunType.asInstanceOf[MethodType].erasedParams)
832-
else None
833-
val ownArgs = erasedCompanion.map { isErased =>
834-
args.zip(isErased).collect { case (arg, isErased) if !isErased => arg }
835-
}.getOrElse(args)
830+
val ownArgs = origFunType match
831+
case mt: MethodType if mt.hasErasedParams =>
832+
args.zip(mt.erasedParams).collect { case (arg, false) => arg }
833+
case _ => args
836834
val fun1 = typedExpr(fun, AnyFunctionProto)
837835
fun1.tpe.widen match
838836
case mt: MethodType =>

compiler/src/dotty/tools/dotc/transform/GenericSignatures.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,8 +312,7 @@ object GenericSignatures {
312312
// erased method parameters do not make it to the bytecode.
313313
def effectiveParamInfoss(t: Type)(using Context): List[List[Type]] = t match {
314314
case t: MethodType if t.hasErasedParams =>
315-
t.paramInfos.zip(t.erasedParams)
316-
.flatMap((i, e) => if e then None else Some(i))
315+
t.paramInfos.zip(t.erasedParams).collect{ case (i, false) => i }
317316
:: effectiveParamInfoss(t.resType)
318317
case t: MethodType => t.paramInfos :: effectiveParamInfoss(t.resType)
319318
case _ => Nil

compiler/src/dotty/tools/dotc/transform/PruneErasedDefs.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,11 @@ class PruneErasedDefs extends MiniPhase with SymTransformer { thisTransform =>
3939
else sym.copySymDenotation(initFlags = sym.flags | Private)
4040

4141
override def transformApply(tree: Apply)(using Context): Tree =
42-
if !tree.fun.tpe.widen.hasErasedParams then tree
43-
else
44-
val erasedParams = tree.fun.tpe.widen.asInstanceOf[MethodType].erasedParams
45-
cpy.Apply(tree)(tree.fun, tree.args.zip(erasedParams).map((a, e) => if e then trivialErasedTree(a) else a))
42+
tree.fun.tpe.widen match
43+
case mt: MethodType if mt.hasErasedParams =>
44+
cpy.Apply(tree)(tree.fun, tree.args.zip(mt.erasedParams).map((a, e) => if e then trivialErasedTree(a) else a))
45+
case _ =>
46+
tree
4647

4748
override def transformValDef(tree: ValDef)(using Context): Tree =
4849
checkErasedInExperimental(tree.symbol)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,7 +1239,6 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
12391239
val pt1 = pt.strippedDealias.normalized
12401240
if (pt1 ne pt1.dropDependentRefinement)
12411241
&& defn.isContextFunctionType(pt1.nonPrivateMember(nme.apply).info.finalResultType)
1242-
&& pt1.nonPrivateMember(nme.apply).info.asInstanceOf[MethodType].isResultDependent
12431242
then
12441243
report.error(
12451244
em"""Implementation restriction: Expected result type $pt1
@@ -1354,8 +1353,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
13541353
val resTpt = TypeTree(mt.nonDependentResultApprox).withSpan(body.span)
13551354
val typeArgs = appDef.termParamss.head.map(_.tpt) :+ resTpt
13561355
val core =
1357-
if mt.hasErasedParams
1358-
then TypeTree(defn.ErasedFunctionClass.typeRef)
1356+
if mt.hasErasedParams then TypeTree(defn.ErasedFunctionClass.typeRef)
13591357
else
13601358
val funSym = defn.FunctionSymbol(numArgs, isContextual, isImpure)
13611359
val tycon = TypeTree(funSym.typeRef)

0 commit comments

Comments
 (0)