From 186a7666625a80e823e4f69c29ba4a38a1868e93 Mon Sep 17 00:00:00 2001 From: Anatolii Date: Thu, 27 Feb 2020 16:11:25 +0100 Subject: [PATCH] Fix #8368: Don't generate forwarders for excluded exports --- compiler/src/dotty/tools/dotc/typer/Namer.scala | 3 ++- tests/neg/exports.check | 6 +----- tests/neg/exports.scala | 2 +- tests/neg/i8368.scala | 11 +++++++++++ tests/pos/i8368.scala | 10 ++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 tests/neg/i8368.scala create mode 100644 tests/pos/i8368.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Namer.scala b/compiler/src/dotty/tools/dotc/typer/Namer.scala index 71faaa9423e7..97f61c6664bd 100644 --- a/compiler/src/dotty/tools/dotc/typer/Namer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Namer.scala @@ -1135,7 +1135,8 @@ class Namer { typer: Typer => if sel.isWildcard then addWildcardForwarders(seen, sel.span) else - addForwardersNamed(sel.name, sel.rename, sel.span) + if sel.rename != nme.WILDCARD then + addForwardersNamed(sel.name, sel.rename, sel.span) addForwarders(sels1, sel.name :: seen) case _ => diff --git a/tests/neg/exports.check b/tests/neg/exports.check index c6cbb43106ce..f691b66444f6 100644 --- a/tests/neg/exports.check +++ b/tests/neg/exports.check @@ -7,17 +7,13 @@ | ^^^^^^^^^^^^^^ | no eligible member scanAll at this.scanUnit | this.scanUnit.scanAll cannot be exported because it is not accessible --- Error: tests/neg/exports.scala:23:27 -------------------------------------------------------------------------------- -23 | export printUnit.{stat => _, _} // error: double definition // error: double definition - | ^^^^^^^^^ - | no eligible member stat at this.printUnit -- Error: tests/neg/exports.scala:25:21 -------------------------------------------------------------------------------- 25 | export printUnit.bitmap // error: no eligible member | ^ | non-private method bitmap in class Copier refers to private value printUnit | in its type signature => Copier.this.printUnit.bitmap.type -- [E120] Duplicate Symbol Error: tests/neg/exports.scala:23:33 -------------------------------------------------------- -23 | export printUnit.{stat => _, _} // error: double definition // error: double definition +23 | export printUnit.{stat => _, _} // error: double definition | ^ | Double definition: | def status: => List[String] in class Copier at line 28 and diff --git a/tests/neg/exports.scala b/tests/neg/exports.scala index 23d2412196cb..1972158bf58e 100644 --- a/tests/neg/exports.scala +++ b/tests/neg/exports.scala @@ -20,7 +20,7 @@ export scanUnit.scanIt // error: no eligible member export scanUnit.{scanAll => foo} // error: no eligible member - export printUnit.{stat => _, _} // error: double definition // error: double definition + export printUnit.{stat => _, _} // error: double definition export scanUnit._ // error: double definition export printUnit.bitmap // error: no eligible member export printUnit.status // error: double definition diff --git a/tests/neg/i8368.scala b/tests/neg/i8368.scala new file mode 100644 index 000000000000..32c4386d94d2 --- /dev/null +++ b/tests/neg/i8368.scala @@ -0,0 +1,11 @@ +trait Foo { + def a = 1 + def b = 1 + def c = 1 +} + +class Bar(foo: Foo) { + export foo.{a => _, b => _, _} + val x1 = a // error + val x2 = b // error +} diff --git a/tests/pos/i8368.scala b/tests/pos/i8368.scala new file mode 100644 index 000000000000..c54fcb27db7b --- /dev/null +++ b/tests/pos/i8368.scala @@ -0,0 +1,10 @@ +trait Foo { + def a = 1 + def b = 1 + def c = 1 +} + +class Bar(foo: Foo) { + export foo.{a => _, b => _, _} + val x1 = c +}