Skip to content

Commit e6033df

Browse files
authored
Merge pull request #152 from scala/backport-lts-3.3-21888
Backport "Resolve name when named imp is behind wild imps" to 3.3 LTS
2 parents d933c40 + 5b12e70 commit e6033df

File tree

11 files changed

+49
-33
lines changed

11 files changed

+49
-33
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ object desugar {
522522
if enumTParams.nonEmpty then
523523
defaultGetters = defaultGetters.map:
524524
case ddef: DefDef =>
525-
val tParams = enumTParams.map(tparam => toMethParam(tparam, KeepAnnotations.All))
525+
val tParams = enumTParams.map(tparam => toDefParam(tparam, keepAnnotations = true))
526526
cpy.DefDef(ddef)(paramss = joinParams(tParams, ddef.trailingParamss))
527527

528528
val (normalizedBody, enumCases, enumCompanionRef) = {

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

+2
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ trait Applications extends Compatibility {
885885
val app1 =
886886
if !success then app0.withType(UnspecifiedErrorType)
887887
else {
888+
if isAnnotConstr(methRef.symbol) && !isJavaAnnotConstr(methRef.symbol) then
889+
typedArgs
888890
if !sameSeq(args, orderedArgs)
889891
&& !isJavaAnnotConstr(methRef.symbol)
890892
&& !typedArgs.forall(isSafeArg)

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

+6
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,12 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
234234
// special cases: definitions beat imports, and named imports beat
235235
// wildcard imports, provided both are in contexts with same scope
236236
found
237+
else if newPrec == WildImport && ctx.outersIterator.exists: ctx =>
238+
ctx.isImportContext && namedImportRef(ctx.importInfo.uncheckedNN).exists
239+
then
240+
// Don't let two ambiguous wildcard imports rule over
241+
// a winning named import. See pos/i18529.
242+
found
237243
else
238244
if !scala2pkg && !previous.isError && !found.isError then
239245
fail(AmbiguousReference(name, newPrec, prevPrec, prevCtx))

tests/pos/i18529/JCode1.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package bug.code;
2+
3+
import bug.util.List;
4+
import bug.util.*;
5+
import java.util.*;
6+
7+
public class JCode1 {
8+
public void m1(List<Integer> xs) { return; }
9+
}

tests/pos/i18529/JCode2.java

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package bug.code;
2+
3+
import bug.util.*;
4+
import bug.util.List;
5+
import java.util.*;
6+
7+
public class JCode2 {
8+
public void m1(List<Integer> xs) { return; }
9+
}

tests/pos/i18529/List.java

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package bug.util;
2+
3+
public final class List<E> {}

tests/pos/i18529/SCode1.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package bug.code
2+
3+
import bug.util.List
4+
import bug.util.*
5+
import java.util.*
6+
7+
class SCode1 {
8+
def work(xs: List[Int]): Unit = {}
9+
}

tests/pos/i18529/SCode2.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package bug.code
2+
3+
import bug.util.*
4+
import bug.util.List
5+
import java.util.*
6+
7+
class SCode2 {
8+
def work(xs: List[Int]): Unit = {}
9+
}

tests/pos/i18529/Test.scala

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
class Test

tests/printing/dependent-annot-default-args.check

-23
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,16 @@ package <empty> {
88
final module class annot() extends AnyRef() { this: annot.type =>
99
def $lessinit$greater$default$2: Any @uncheckedVariance = 42
1010
}
11-
class annot2(x: Any, y: Array[Any]) extends annotation.Annotation() {
12-
private[this] val x: Any
13-
private[this] val y: Array[Any]
14-
}
15-
final lazy module val annot2: annot2 = new annot2()
16-
final module class annot2() extends AnyRef() { this: annot2.type =>
17-
def $lessinit$greater$default$1: Any @uncheckedVariance = -1
18-
def $lessinit$greater$default$2: Array[Any] @uncheckedVariance =
19-
Array.apply[Any](["Hello" : Any]*)(scala.reflect.ClassTag.Any)
20-
}
2111
final lazy module val dependent-annot-default-args$package:
2212
dependent-annot-default-args$package =
2313
new dependent-annot-default-args$package()
2414
final module class dependent-annot-default-args$package() extends Object() {
2515
this: dependent-annot-default-args$package.type =>
2616
def f(x: Int): Int @annot(x) = x
27-
def f2(x: Int):
28-
Int @annot2(
29-
y = Array.apply[Any](["Hello",x : Any]*)(scala.reflect.ClassTag.Any))
30-
= x
3117
def test: Unit =
3218
{
3319
val y: Int = ???
3420
val z: Int @annot(y) = f(y)
35-
val z2:
36-
Int @annot2(
37-
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any)
38-
)
39-
= f2(y)
40-
@annot(44) val z3: Int = 45
41-
@annot2(
42-
y = Array.apply[Any](["Hello",y : Any]*)(scala.reflect.ClassTag.Any))
43-
val z4: Int = 45
4421
()
4522
}
4623
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
11
class annot(x: Any, y: Any = 42) extends annotation.Annotation
2-
class annot2(x: Any = -1, y: Array[Any] = Array("Hello")) extends annotation.Annotation
3-
42
def f(x: Int): Int @annot(x) = x
5-
def f2(x: Int): Int @annot2(y = Array("Hello", x)) = x
63

74
def test =
85
val y: Int = ???
9-
106
val z = f(y)
11-
val z2 = f2(y)
12-
13-
@annot(44) val z3 = 45
14-
@annot2(y = Array("Hello", y)) val z4 = 45
15-

0 commit comments

Comments
 (0)