Skip to content

Commit 801e3ea

Browse files
committed
Address review comments
- Clearer code for skipped whynoMatchStr - Surivive missing ExportForwarders attachments - Add tests with self-referential exports
1 parent f36c5d9 commit 801e3ea

File tree

4 files changed

+27
-4
lines changed

4 files changed

+27
-4
lines changed

compiler/src/dotty/tools/dotc/typer/Namer.scala

+5-2
Original file line numberDiff line numberDiff line change
@@ -936,6 +936,9 @@ class Namer { typer: Typer =>
936936
/** Add forwarders as required by the export statements in this class */
937937
private def processExports(implicit ctx: Context): Unit = {
938938

939+
/** A string indicating that no forwarders for this kind of symbol are emitted */
940+
val SKIP = "(skip)"
941+
939942
/** The forwarders defined by export `exp`.
940943
*/
941944
def exportForwarders(exp: Export): List[tpd.MemberDef] = {
@@ -948,7 +951,7 @@ class Namer { typer: Typer =>
948951
val sym = mbr.symbol
949952
if (sym.is(ImplicitOrImplied) != exp.impliedOnly) s"is ${if (exp.impliedOnly) "not " else ""}implied"
950953
else if (!sym.isAccessibleFrom(path.tpe)) "is not accessible"
951-
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) "_"
954+
else if (sym.isConstructor || sym.is(ModuleClass) || sym.is(Bridge)) SKIP
952955
else if (cls.derivesFrom(sym.owner) &&
953956
(sym.owner == cls || !sym.is(Deferred))) i"is already a member of $cls"
954957
else ""
@@ -1007,7 +1010,7 @@ class Namer { typer: Typer =>
10071010
val mbrs = List(name, name.toTypeName).flatMap(path.tpe.member(_).alternatives)
10081011
mbrs.foreach(addForwarder(alias, _, span))
10091012
if (buf.size == size) {
1010-
val reason = mbrs.map(whyNoForwarder).dropWhile(_ == "-") match {
1013+
val reason = mbrs.map(whyNoForwarder).dropWhile(_ == SKIP) match {
10111014
case Nil => ""
10121015
case why :: _ => i"\n$path.$name cannot be exported because it $why"
10131016
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -2160,7 +2160,8 @@ class Typer extends Namer
21602160
case Thicket(stats) :: rest =>
21612161
traverse(stats ++ rest)
21622162
case (stat: untpd.Export) :: rest =>
2163-
buf ++= stat.attachment(ExportForwarders)
2163+
buf ++= stat.attachmentOrElse(ExportForwarders, Nil)
2164+
// no attachment can happen in case of cyclic references
21642165
traverse(rest)
21652166
case stat :: rest =>
21662167
val stat1 = typed(stat)(ctx.exprContext(stat, exprOwner))

tests/neg/exports.scala

+15-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,18 @@ trait IterableOps[+A, +CC[_], +C] {
3434

3535
export this.{concat => ++} // error: no eligible member
3636

37-
}
37+
}
38+
39+
class Foo {
40+
val foo : Foo = new Foo
41+
export foo.foo // error: no eligible member
42+
}
43+
44+
class Baz {
45+
val bar: Bar = new Bar // error: cyclic reference
46+
export bar._
47+
}
48+
class Bar {
49+
val baz: Baz = new Baz
50+
export baz._
51+
}

tests/run/exports.scala

+5
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ object Test extends App {
2929
Copier.cfg
3030
Copier.config
3131
Copier.config2
32+
}
33+
34+
final class Foo {
35+
lazy val foo : Foo = new Foo
36+
export foo._ // nothing is exported
3237
}

0 commit comments

Comments
 (0)