Skip to content

Commit c077aab

Browse files
committed
Do not dealias in FunctionNOf extractor
1 parent 97febd6 commit c077aab

File tree

8 files changed

+17
-18
lines changed

8 files changed

+17
-18
lines changed

compiler/src/dotty/tools/dotc/cc/CheckCaptures.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -408,9 +408,9 @@ class CheckCaptures extends Recheck, SymTransformer:
408408
else if meth == defn.Caps_unsafeUnbox then
409409
mapArgUsing(_.forceBoxStatus(false))
410410
else if meth == defn.Caps_unsafeBoxFunArg then
411-
mapArgUsing:
412-
case defn.FunctionOf(mt: MethodType) if !mt.isResultDependent =>
413-
defn.FunctionOf(mt.derivedLambdaType(resType = mt.resType.forceBoxStatus(true)))
411+
mapArgUsing: tp =>
412+
val defn.FunctionOf(mt: MethodType) = tp.dealias: @unchecked
413+
defn.FunctionOf(mt.derivedLambdaType(resType = mt.resType.forceBoxStatus(true)))
414414
else
415415
super.recheckApply(tree, pt) match
416416
case appType @ CapturingType(appType1, refs) =>
@@ -704,7 +704,7 @@ class CheckCaptures extends Recheck, SymTransformer:
704704
if eparent1 eq eparent then expected
705705
else CapturingType(eparent1, refs, boxed = expected0.isBoxed)
706706
case defn.FunctionOf(mt: MethodType) =>
707-
actual match
707+
actual.dealias match
708708
case defn.FunctionOf(mt2: MethodType) if mt2.isResultDependent =>
709709
mt.toFunctionType(isJava = false, alwaysDependent = true)
710710
case _ =>

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,11 +1141,10 @@ class Definitions {
11411141
/** Matches a (possibly aliased) `FunctionN[...]` or `ContextFunctionN[...]`.
11421142
* Extracts the list of function argument types, the result type and whether function is contextual.
11431143
*/
1144-
def unapply(ft: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
1145-
val dft = ft.dealias
1146-
val tsym = dft.typeSymbol
1147-
if isFunctionSymbol(tsym) && ft.isRef(tsym) then
1148-
val targs = dft.argInfos
1144+
def unapply(tpe: Type)(using Context): Option[(List[Type], Type, Boolean)] = {
1145+
val tsym = tpe.typeSymbol
1146+
if isFunctionSymbol(tsym) && tpe.isRef(tsym) then
1147+
val targs = tpe.argInfos
11491148
if (targs.isEmpty) None
11501149
else Some(targs.init, targs.last, tsym.name.isContextFunction)
11511150
else None

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ class Bridges(root: ClassSymbol, thisPhase: DenotTransformer)(using Context) {
130130
ctx.typer.typed(untpd.cpy.Apply(ref)(ref, args), member.info.finalResultType)
131131
else
132132
val mtWithoutErasedParams = atPhase(erasurePhase) {
133-
tp match
133+
tp.dealias match
134134
case defn.FunctionOf(mt: MethodType) =>
135135
val paramInfos = mt.paramInfos.zip(mt.erasedParams).collect { case (param, false) => param }
136136
mt.derivedLambdaType(paramInfos = paramInfos)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ object ContextFunctionResults:
1919
* consists of a string of `n` nested context closures.
2020
*/
2121
def annotateContextResults(mdef: DefDef)(using Context): Unit =
22-
def contextResultCount(rhs: Tree, tp: Type): Int = tp match
22+
def contextResultCount(rhs: Tree, tp: Type): Int = tp.dealias match
2323
case defn.FunctionOf(mt) if mt.isContextualMethod =>
2424
rhs match
2525
case closureDef(meth) => 1 + contextResultCount(meth.rhs, mt.resType)
@@ -68,7 +68,7 @@ object ContextFunctionResults:
6868
*/
6969
def integrateContextResults(tp: Type, crCount: Int)(using Context): Type =
7070
if crCount == 0 then tp
71-
else tp match
71+
else tp.dealias match
7272
case ExprType(rt) =>
7373
integrateContextResults(rt, crCount)
7474
case tp: MethodOrPoly =>
@@ -113,7 +113,7 @@ object ContextFunctionResults:
113113
else tree match
114114
case Select(qual, name) =>
115115
if name == nme.apply then
116-
qual.tpe match
116+
qual.tpe.nn.dealias match
117117
case defn.FunctionOf(mt) if mt.isContextualMethod =>
118118
integrateSelect(qual, n + 1)
119119
case _ if defn.isContextFunctionClass(tree.symbol.maybeOwner) => // for TermRefs

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,7 +1974,7 @@ trait Applications extends Compatibility {
19741974
def paramCount(ref: TermRef) =
19751975
val formals = ref.widen.firstParamTypes
19761976
if formals.length > idx then
1977-
formals(idx) match
1977+
formals(idx).dealias match
19781978
case defn.FunctionNOf(args, _, _) => args.length
19791979
case _ => -1
19801980
else -1
@@ -2060,7 +2060,7 @@ trait Applications extends Compatibility {
20602060
else resolveMapped(alts1, _.widen.appliedTo(targs1.tpes), pt1)
20612061

20622062
case pt =>
2063-
val compat0 = pt match
2063+
val compat0 = pt.dealias match
20642064
case defn.FunctionNOf(args, resType, _) =>
20652065
narrowByTypes(alts, args, resType)
20662066
case _ =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ object ErrorReporting {
166166
val normTp = normalize(tree.tpe, pt)
167167
val normPt = normalize(pt, pt)
168168

169-
def contextFunctionCount(tp: Type): Int = tp.stripped match
169+
def contextFunctionCount(tp: Type): Int = tp.stripped.dealias match
170170
// TODO handle result-dependent functions?
171171
case defn.FunctionOf(mt) if mt.isContextualMethod && !mt.isResultDependent => 1 + contextFunctionCount(mt.resType)
172172
case _ => 0

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1892,7 +1892,7 @@ class Namer { typer: Typer =>
18921892
def expectedDefaultArgType =
18931893
val originalTp = defaultParamType
18941894
val approxTp = wildApprox(originalTp)
1895-
approxTp.stripPoly match
1895+
approxTp.dealias.stripPoly match
18961896
case defn.FunctionOf(mt)
18971897
if mt.isContextualMethod && (
18981898
mt.isResultDependent || // in this case `resType` is lying, gives us only the non-dependent upper bound

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ object ProtoTypes {
383383
def allArgTypesAreCurrent()(using Context): Boolean =
384384
state.typedArg.size == args.length
385385

386-
private def isUndefined(tp: Type): Boolean = tp match {
386+
private def isUndefined(tp: Type): Boolean = tp.dealias match {
387387
case _: WildcardType => true
388388
case defn.FunctionNOf(args, result, _) => args.exists(isUndefined) || isUndefined(result)
389389
case _ => false

0 commit comments

Comments
 (0)