Skip to content

Backport "Resolve name when named imp is behind wild imps" to 3.3 LTS #152

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 6 commits into from
Mar 13, 2025
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
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ object desugar {
if enumTParams.nonEmpty then
defaultGetters = defaultGetters.map:
case ddef: DefDef =>
val tParams = enumTParams.map(tparam => toMethParam(tparam, KeepAnnotations.All))
val tParams = enumTParams.map(tparam => toDefParam(tparam, keepAnnotations = true))
cpy.DefDef(ddef)(paramss = joinParams(tParams, ddef.trailingParamss))

val (normalizedBody, enumCases, enumCompanionRef) = {
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -885,6 +885,8 @@ trait Applications extends Compatibility {
val app1 =
if !success then app0.withType(UnspecifiedErrorType)
else {
if isAnnotConstr(methRef.symbol) && !isJavaAnnotConstr(methRef.symbol) then
typedArgs
if !sameSeq(args, orderedArgs)
&& !isJavaAnnotConstr(methRef.symbol)
&& !typedArgs.forall(isSafeArg)
Expand Down
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 @@ -234,6 +234,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
23 changes: 0 additions & 23 deletions tests/printing/dependent-annot-default-args.check
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,16 @@ package <empty> {
final module class annot() extends AnyRef() { this: annot.type =>
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
}
class annot2(x: Any, y: Array[Any]) extends annotation.Annotation() {
private[this] val x: Any
private[this] val y: Array[Any]
}
final lazy module val annot2: annot2 = new annot2()
final module class annot2() extends AnyRef() { this: annot2.type =>
def $lessinit$greater$default$1: Any @uncheckedVariance = -1
def $lessinit$greater$default$2: Array[Any] @uncheckedVariance =
Array.apply[Any](["Hello" : Any]*)(scala.reflect.ClassTag.Any)
}
final lazy module val dependent-annot-default-args$package:
dependent-annot-default-args$package =
new dependent-annot-default-args$package()
final module class dependent-annot-default-args$package() extends Object() {
this: dependent-annot-default-args$package.type =>
def f(x: Int): Int @annot(x) = x
def f2(x: Int):
Int @annot2(
y = Array.apply[Any](["Hello",x : Any]*)(scala.reflect.ClassTag.Any))
= x
def test: Unit =
{
val y: Int = ???
val z: Int @annot(y) = f(y)
val z2:
Int @annot2(
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any)
)
= f2(y)
@annot(44) val z3: Int = 45
@annot2(
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any))
val z4: Int = 45
()
}
}
Expand Down
9 changes: 0 additions & 9 deletions tests/printing/dependent-annot-default-args.scala
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
class annot(x: Any, y: Any = 42) extends annotation.Annotation
class annot2(x: Any = -1, y: Array[Any] = Array("Hello")) extends annotation.Annotation

def f(x: Int): Int @annot(x) = x
def f2(x: Int): Int @annot2(y = Array("Hello", x)) = x

def test =
val y: Int = ???

val z = f(y)
val z2 = f2(y)

@annot(44) val z3 = 45
@annot2(y = Array("Hello", y)) val z4 = 45