Skip to content

Commit b5b7fa5

Browse files
authored
Merge pull request #144 from scala/backport-lts-3.3-22142
Backport "Type avoidance in MT bound inference" to 3.3 LTS
2 parents 7c169f5 + be7c860 commit b5b7fa5

File tree

6 files changed

+15
-20
lines changed

6 files changed

+15
-20
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
11271127
/** Replace Ident nodes references to the underlying tree that defined them */
11281128
def underlying(using Context): Tree = MapToUnderlying().transform(tree)
11291129

1130+
/** Collect all the TypeSymbol's of the type Bind nodes in the tree. */
1131+
def bindTypeSymbols(using Context): List[TypeSymbol] =
1132+
tree.collectSubTrees { case b: Bind if b.isType => b.symbol.asType }
1133+
11301134
// --- Higher order traversal methods -------------------------------
11311135

11321136
/** Apply `f` to each subtree of this tree */

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4557,6 +4557,7 @@ object Types extends TypeUtils {
45574557
*/
45584558
def isUnreducibleWild(using Context): Boolean =
45594559
tycon.isLambdaSub && hasWildcardArg && !isMatchAlias
4560+
&& !(args.sizeIs == 1 && defn.isCompiletime_S(tycon.typeSymbol)) // S is a pseudo Match Alias
45604561

45614562
def tryCompiletimeConstantFold(using Context): Type =
45624563
if myEvalRunId == ctx.runId then myEvalued

compiler/src/dotty/tools/dotc/inlines/InlineReducer.scala

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,31 +216,21 @@ class InlineReducer(inliner: Inliner)(using Context):
216216
type TypeBindsMap = SimpleIdentityMap[TypeSymbol, java.lang.Boolean]
217217

218218
def getTypeBindsMap(pat: Tree, tpt: Tree): TypeBindsMap = {
219-
val getBinds = new TreeAccumulator[Set[TypeSymbol]] {
220-
def apply(syms: Set[TypeSymbol], t: Tree)(using Context): Set[TypeSymbol] = {
221-
val syms1 = t match {
222-
case t: Bind if t.symbol.isType =>
223-
syms + t.symbol.asType
224-
case _ => syms
225-
}
226-
foldOver(syms1, t)
227-
}
228-
}
229-
230219
// Extractors can contain Bind nodes in type parameter lists,
231220
// for that case tree looks like this:
232221
// UnApply[t @ t](pats)(implicits): T[t]
233222
// Test case is pos/inline-caseclass.scala.
223+
//
234224
// Alternatively, for explicitly specified type binds in type annotations like in
235225
// case A(B): A[t]
236226
// the tree will look like this:
237227
// Unapply[t](pats)(implicits) : T[t @ t]
238228
// and the binds will be found in the type tree instead
239229
// Test case is pos-macros/i15971
240-
val tptBinds = getBinds(Set.empty[TypeSymbol], tpt)
230+
val tptBinds = tpt.bindTypeSymbols.toSet
241231
val binds: Set[TypeSymbol] = pat match {
242232
case UnApply(TypeApply(_, tpts), _, _) =>
243-
getBinds(Set.empty[TypeSymbol], tpts) ++ tptBinds
233+
tpts.flatMap(_.bindTypeSymbols).toSet ++ tptBinds
244234
case _ => tptBinds
245235
}
246236

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -421,13 +421,7 @@ trait TypeAssigner {
421421
def assignType(tree: untpd.CaseDef, pat: Tree, body: Tree)(using Context): CaseDef = {
422422
val ownType =
423423
if (body.isType) {
424-
val getParams = new TreeAccumulator[mutable.ListBuffer[TypeSymbol]] {
425-
def apply(ps: mutable.ListBuffer[TypeSymbol], t: Tree)(using Context) = t match {
426-
case t: Bind if t.symbol.isType => foldOver(ps += t.symbol.asType, t)
427-
case _ => foldOver(ps, t)
428-
}
429-
}
430-
val params1 = getParams(new mutable.ListBuffer[TypeSymbol](), pat).toList
424+
val params1 = pat.bindTypeSymbols
431425
val params2 = pat.tpe match
432426
case AppliedType(tycon, args) =>
433427
val tparams = tycon.typeParamSymbols

compiler/test/dotc/pos-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ i12299a.scala
1919
i13871.scala
2020
i15181.scala
2121
i15922.scala
22+
i15926.scala
2223
t5031_2.scala
2324
i16997.scala
2425
i7414.scala

tests/pos/i21256.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
object Test {
2+
type MTWithBind[X] = X match {
3+
case List[t] => t
4+
}
5+
}

0 commit comments

Comments
 (0)