@@ -115,8 +115,18 @@ object Checking {
115
115
val parent1 = this (parent)
116
116
val saved = cycleOK
117
117
cycleOK = nestedCycleOK
118
- try tp.derivedRefinedType(parent1, name, this (tp.refinedInfo))
119
- finally cycleOK = saved
118
+
119
+ /** A derived refined type with two possible tweaks:
120
+ * (1) LazyRefs in parents are pulled out,
121
+ * (2) #Apply is added if the type is a fully applied type lambda.
122
+ */
123
+ def derivedType (p : Type ): Type = p match {
124
+ case p : LazyRef => LazyRef (() => derivedType(p.ref))
125
+ case _ =>
126
+ val res = tp.derivedRefinedType(p, name, this (tp.refinedInfo))
127
+ if (res.isSafeLambda && res.typeParams.isEmpty) res.select(tpnme.Apply ) else res
128
+ }
129
+ try derivedType(parent1) finally cycleOK = saved
120
130
case tp @ TypeRef (pre, name) =>
121
131
try {
122
132
// A prefix is interesting if it might contain (transitively) a reference
@@ -130,6 +140,9 @@ object Checking {
130
140
case SuperType (thistp, _) => isInteresting(thistp)
131
141
case AndType (tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
132
142
case OrType (tp1, tp2) => isInteresting(tp1) && isInteresting(tp2)
143
+ case _ : RefinedType => false
144
+ // Note: it's important not to visit parents of RefinedTypes,
145
+ // since otherwise spurious #Apply projections might be inserted.
133
146
case _ => false
134
147
}
135
148
// If prefix is interesting, check info of typeref recursively, marking the referred symbol
@@ -158,6 +171,9 @@ object Checking {
158
171
* @pre sym is not yet initialized (i.e. its type is a Completer).
159
172
* @return `info` where every legal F-bounded reference is proctected
160
173
* by a `LazyRef`, or `ErrorType` if a cycle was detected and reported.
174
+ * Furthermore: Add an #Apply to a fully instantiated type lambda, if none was
175
+ * given before. This is necessary here because sometimes type lambdas are not
176
+ * recognized when they are first formed.
161
177
*/
162
178
def checkNonCyclic (sym : Symbol , info : Type , reportErrors : Boolean )(implicit ctx : Context ): Type = {
163
179
val checker = new CheckNonCyclicMap (sym, reportErrors)(ctx.addMode(Mode .CheckCyclic ))
0 commit comments