@@ -115,8 +115,18 @@ object Checking {
115115 val parent1 = this (parent)
116116 val saved = cycleOK
117117 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
120130 case tp @ TypeRef (pre, name) =>
121131 try {
122132 // A prefix is interesting if it might contain (transitively) a reference
@@ -130,6 +140,9 @@ object Checking {
130140 case SuperType (thistp, _) => isInteresting(thistp)
131141 case AndType (tp1, tp2) => isInteresting(tp1) || isInteresting(tp2)
132142 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.
133146 case _ => false
134147 }
135148 // If prefix is interesting, check info of typeref recursively, marking the referred symbol
@@ -158,6 +171,9 @@ object Checking {
158171 * @pre sym is not yet initialized (i.e. its type is a Completer).
159172 * @return `info` where every legal F-bounded reference is proctected
160173 * 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.
161177 */
162178 def checkNonCyclic (sym : Symbol , info : Type , reportErrors : Boolean )(implicit ctx : Context ): Type = {
163179 val checker = new CheckNonCyclicMap (sym, reportErrors)(ctx.addMode(Mode .CheckCyclic ))
0 commit comments