@@ -245,9 +245,11 @@ object ExplicitOuter {
245245 private def hasOuter (cls : ClassSymbol )(using Context ): Boolean =
246246 needsOuterIfReferenced(cls) && outerAccessor(cls).exists
247247
248- /** Class constructor takes an outer argument. Can be called only after phase ExplicitOuter. */
249- def hasOuterParam (cls : ClassSymbol )(using Context ): Boolean =
250- ! cls.is(Trait ) && needsOuterIfReferenced(cls) && outerAccessor(cls).exists
248+ /** Class constructor needs an outer argument. Can be called only after phase ExplicitOuter. */
249+ def needsOuterParam (cls : ClassSymbol )(using Context ): Boolean =
250+ ! cls.is(Trait ) && needsOuterIfReferenced(cls) && (
251+ cls.is(JavaDefined ) || // java inner class doesn't has outer accessor
252+ outerAccessor(cls).exists)
251253
252254 /** Tree references an outer class of `cls` which is not a static owner.
253255 */
@@ -357,7 +359,7 @@ object ExplicitOuter {
357359
358360 /** If `cls` has an outer parameter add one to the method type `tp`. */
359361 def addParam (cls : ClassSymbol , tp : Type ): Type =
360- if (hasOuterParam (cls)) {
362+ if (needsOuterParam (cls)) {
361363 val mt @ MethodTpe (pnames, ptypes, restpe) = tp
362364 mt.derivedLambdaType(
363365 nme.OUTER :: pnames, outerClass(cls).typeRef :: ptypes, restpe)
@@ -378,7 +380,7 @@ object ExplicitOuter {
378380 case TypeApply (Select (r, nme.asInstanceOf_), args) =>
379381 outerArg(r) // cast was inserted, skip
380382 }
381- if (hasOuterParam (cls))
383+ if (needsOuterParam (cls))
382384 methPart(fun) match {
383385 case Select (receiver, _) => outerArg(receiver).withSpan(fun.span) :: Nil
384386 }
@@ -390,7 +392,7 @@ object ExplicitOuter {
390392 * argument, the singleton list with the argument, otherwise Nil.
391393 */
392394 def argsForNew (cls : ClassSymbol , tpe : Type ): List [Tree ] =
393- if (hasOuterParam (cls)) singleton(fixThis(outerPrefix(tpe))) :: Nil
395+ if (needsOuterParam (cls)) singleton(fixThis(outerPrefix(tpe))) :: Nil
394396 else Nil
395397
396398 /** A path of outer accessors starting from node `start`. `start` defaults to the
0 commit comments