Skip to content

Commit 835dea2

Browse files
authored
Merge pull request #285 from scala/backport-lts-3.3-22712
Backport "Rename on import is never wildcard" to 3.3 LTS
2 parents a87b564 + fdf7cdc commit 835dea2

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

+4-1
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,11 @@ class CheckUnused private (phaseMode: PhaseMode, suffix: String) extends MiniPha
275275
case sel :: sels =>
276276
val matches =
277277
if sel.isWildcard then
278+
// if name is different from sym.name, it must be a rename on import, not a wildcard selector
279+
!name.exists(_.toTermName != sym.name.toTermName)
278280
// the qualifier must have the target symbol as a member
279-
hasAltMember(sym.name) && {
281+
&& hasAltMember(sym.name)
282+
&& {
280283
if sel.isGiven then // Further check that the symbol is a given or implicit and conforms to the bound
281284
sym.isOneOf(GivenOrImplicit)
282285
&& (sel.bound.isEmpty || sym.info.finalResultType <:< sel.boundTpe)

tests/warn/i15503a.scala

+7
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,10 @@ object Suppressed:
321321
object Suppressing:
322322
import Suppressed.* // no warn, see options
323323
def f = 42
324+
325+
package i22692:
326+
import javax.swing.*
327+
import javax.swing.event as swingEvent // no warn, regression test for warning in 3.6
328+
329+
type b = AbstractButton
330+
type t = swingEvent.AncestorListener

tests/warn/i15503f.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,10 @@ package givens:
5757
trait Y:
5858
def doY: String
5959

60-
given X:
60+
given X with
6161
def doX = 7
6262

63-
given X => Y: // warn protected param to given class
63+
given (using X): Y with // warn protected param to given class
6464
def doY = "7"
6565
/* desugared. It is protected so that its type can be used in member defs without leaking.
6666
* possibly it should be protected only for named parameters.
@@ -72,6 +72,6 @@ package givens:
7272
new givens.given_Y(using x$1)()
7373
*/
7474

75-
given namely: (x: X) => Y: // warn protected param to given class
75+
given namely (using x: X): Y with // warn protected param to given class
7676
def doY = "8"
7777
end givens

0 commit comments

Comments
 (0)