Skip to content

Commit 9d8f485

Browse files
committed
Denote prefix of constructor pats in type params 2/2
A similar problem as the previous commit arose in etaExpand. Use the rewritten type parameters in typeNew. Now we can add the test.
1 parent d428b87 commit 9d8f485

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

src/compiler/scala/tools/nsc/typechecker/Typers.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4470,13 +4470,16 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper
44704470
// typedTypeConstructor dealiases nothing now, but it makes sense for a "new" to always be
44714471
// given a dealiased type.
44724472
val tpt0 = typedTypeConstructor(tpt) modifyType (_.dealias)
4473-
if (checkStablePrefixClassType(tpt0))
4474-
if (tpt0.hasSymbolField && !tpt0.symbol.typeParams.isEmpty) {
4475-
context.undetparams = cloneSymbols(tpt0.symbol.typeParams)
4476-
notifyUndetparamsAdded(context.undetparams)
4477-
TypeTree().setOriginal(tpt0)
4478-
.setType(appliedType(tpt0.tpe, context.undetparams map (_.tpeHK))) // @PP: tpeHK! #3343, #4018, #4347.
4479-
} else tpt0
4473+
4474+
if (checkStablePrefixClassType(tpt0)) {
4475+
tpt0.tpe.normalize match { // eta-expand
4476+
case PolyType(undet, appliedToUndet) =>
4477+
context.undetparams = undet // can reuse these type params, they're fresh
4478+
notifyUndetparamsAdded(undet)
4479+
TypeTree().setOriginal(tpt0).setType(appliedToUndet)
4480+
case _ => tpt0
4481+
}
4482+
}
44804483
else tpt0
44814484
}
44824485

src/reflect/scala/reflect/internal/Types.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2495,7 +2495,15 @@ trait Types
24952495
// must initialise symbol, see test/files/pos/ticket0137.scala
24962496
val tpars = initializedTypeParams
24972497
if (tpars.isEmpty) this
2498-
else typeFunAnon(tpars, copyTypeRef(this, pre, sym, tpars map (_.tpeHK))) // todo: also beta-reduce?
2498+
else {
2499+
// Since we're going to lose the information denoted by the prefix when pulling the type params
2500+
// out for use as binders in the PolyType, we must eagerly rewrite their infos using relativize
2501+
// to preserve that knowledge.
2502+
val denotedTpars = cloneSymbolsAndModify(tpars, relativize)
2503+
2504+
// @PP: use typeConstructor! #3343, #4018, #4347.
2505+
PolyType(denotedTpars, TypeRef(pre, sym, denotedTpars map (_.typeConstructor)))
2506+
}
24992507
}
25002508

25012509
// only need to rebind type aliases, as typeRef already handles abstract types
@@ -4064,14 +4072,6 @@ trait Types
40644072
@deprecated("use genPolyType(...) instead", "2.10.0") // Used in reflection API
40654073
def polyType(params: List[Symbol], tpe: Type): Type = GenPolyType(params, tpe)
40664074

4067-
/** A creator for anonymous type functions, where the symbol for the type function still needs to be created.
4068-
*
4069-
* TODO:
4070-
* type params of anonymous type functions, which currently can only arise from normalising type aliases, are owned by the type alias of which they are the eta-expansion
4071-
* higher-order subtyping expects eta-expansion of type constructors that arise from a class; here, the type params are owned by that class, but is that the right thing to do?
4072-
*/
4073-
def typeFunAnon(tps: List[Symbol], body: Type): Type = typeFun(tps, body)
4074-
40754075
/** A creator for a type functions, assuming the type parameters tps already have the right owner. */
40764076
def typeFun(tps: List[Symbol], body: Type): Type = PolyType(tps, body)
40774077

test/files/pos/t11103.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Outer[O] {
2+
case class C[T <: O](x: T, y: Outer.this.type)
3+
}
4+
5+
object Foo extends Outer[String]
6+
7+
class Tst {
8+
val c = new Foo.C("a", Foo)
9+
c match {
10+
case Foo.C(a, o) => a
11+
}
12+
}

0 commit comments

Comments
 (0)