@@ -327,40 +327,53 @@ object Checking {
327
327
* to a private type or value which is invisible at a point where `M` is still
328
328
* visible. As an exception, we allow references to type aliases if the underlying
329
329
* type of the alias is not a leak. So type aliases are transparent as far as
330
- * leak testing is concerned. See 997.scala for tests.
330
+ * leak testing is concerned.
331
+ * @return The `info` of `sym`, with problematic aliases expanded away.
332
+ * See i997.scala for tests, i1130.scala for a case where it matters that we
333
+ * transform leaky aliases away.
331
334
*/
332
- def checkNoPrivateLeaks (tree : MemberDef )(implicit ctx : Context ): Unit = {
333
- type Errors = List [( String , Position )]
334
- val sym = tree.symbol
335
- val notPrivate = new TypeAccumulator [ Errors ] {
335
+ def checkNoPrivateLeaks (sym : Symbol , pos : Position )(implicit ctx : Context ): Type = {
336
+ class NotPrivate extends TypeMap {
337
+ type Errors = List [( String , Position )]
338
+ var errors : Errors = Nil
336
339
def accessBoundary (sym : Symbol ): Symbol =
337
340
if (sym.is(Private )) sym.owner
338
341
else if (sym.privateWithin.exists) sym.privateWithin
339
342
else if (sym.is(Package )) sym
340
343
else accessBoundary(sym.owner)
341
- def apply (errors : Errors , tp : Type ): Errors = tp match {
344
+ def apply (tp : Type ): Type = tp match {
342
345
case tp : NamedType =>
343
- val errors1 =
346
+ val prevErrors = errors
347
+ var tp1 =
344
348
if (tp.symbol.is(Private ) &&
345
- ! accessBoundary(sym).isContainedIn(tp.symbol.owner)) {
346
- (d " non-private $sym refers to private ${tp.symbol}\n in its type signature ${sym.info}" , tree.pos) :: errors
347
- } else foldOver(errors, tp)
348
- if ((errors1 ne errors) && tp.info.isAlias) {
349
+ ! accessBoundary(sym).isContainedIn(tp.symbol.owner)) {
350
+ errors = (d " non-private $sym refers to private ${tp.symbol}\n in its type signature ${sym.info}" ,
351
+ pos) :: errors
352
+ tp
353
+ }
354
+ else mapOver(tp)
355
+ if ((errors ne prevErrors) && tp.info.isAlias) {
349
356
// try to dealias to avoid a leak error
350
- val errors2 = apply(errors, tp.info.bounds.hi)
351
- if (errors2 eq errors) errors2
352
- else errors1
353
- } else errors1
357
+ val savedErrors = errors
358
+ errors = prevErrors
359
+ val tp2 = apply(tp.info.bounds.hi)
360
+ if (errors eq prevErrors) tp1 = tp2
361
+ else errors = savedErrors
362
+ }
363
+ tp1
354
364
case tp : ClassInfo =>
355
- (apply(errors, tp.prefix) /: tp.parentsWithArgs)(apply)
365
+ tp.derivedClassInfo(
366
+ prefix = apply(tp.prefix),
367
+ classParents = tp.parentsWithArgs.map(p =>
368
+ apply(p).underlyingClassRef(refinementOK = false ).asInstanceOf [TypeRef ]))
356
369
case _ =>
357
- foldOver(errors, tp)
370
+ mapOver( tp)
358
371
}
359
372
}
360
- if ( ! sym.is( SyntheticOrPrivate ) && sym.owner.isClass) {
361
- val errors = notPrivate(Nil , sym.info)
362
- errors.foreach { case (msg, pos) => ctx.errorOrMigrationWarning(msg, pos) }
363
- }
373
+ val notPrivate = new NotPrivate
374
+ val info = notPrivate(sym.info)
375
+ notPrivate. errors.foreach { case (msg, pos) => ctx.errorOrMigrationWarning(msg, pos) }
376
+ info
364
377
}
365
378
}
366
379
0 commit comments