Skip to content

Resolve name when named imp is behind wild imps #21888

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
// special cases: definitions beat imports, and named imports beat
// wildcard imports, provided both are in contexts with same scope
found
else if newPrec == WildImport && ctx.outersIterator.exists: ctx =>
ctx.isImportContext && namedImportRef(ctx.importInfo.uncheckedNN).exists
then
// Don't let two ambiguous wildcard imports rule over
// a winning named import. See pos/i18529.
found
else
if !scala2pkg && !previous.isError && !found.isError then
fail(AmbiguousReference(name, newPrec, prevPrec, prevCtx,
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i18529/JCode1.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bug.code;

import bug.util.List;
import bug.util.*;
import java.util.*;

public class JCode1 {
public void m1(List<Integer> xs) { return; }
}
9 changes: 9 additions & 0 deletions tests/pos/i18529/JCode2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bug.code;

import bug.util.*;
import bug.util.List;
import java.util.*;

public class JCode2 {
public void m1(List<Integer> xs) { return; }
}
3 changes: 3 additions & 0 deletions tests/pos/i18529/List.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package bug.util;

public final class List<E> {}
9 changes: 9 additions & 0 deletions tests/pos/i18529/SCode1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bug.code

import bug.util.List
import bug.util.*
import java.util.*

class SCode1 {
def work(xs: List[Int]): Unit = {}
}
9 changes: 9 additions & 0 deletions tests/pos/i18529/SCode2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package bug.code

import bug.util.*
import bug.util.List
import java.util.*

class SCode2 {
def work(xs: List[Int]): Unit = {}
}
1 change: 1 addition & 0 deletions tests/pos/i18529/Test.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
class Test
Loading