Skip to content

Commit 14909dd

Browse files
committed
Construct ref more correctly
1 parent da1e073 commit 14909dd

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4352,23 +4352,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43524352
val allDenots = ref.denot.alternatives
43534353
if pt.isExtensionApplyProto then allDenots.filter(_.symbol.is(ExtensionMethod))
43544354
else allDenots
4355+
def altRef(alt: SingleDenotation) = TermRef(ref.prefix, ref.name, alt)
4356+
val alts = altDenots.map(altRef)
43554357

43564358
typr.println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%\n\n %")
43574359

43584360
/** Search for an alternative that does not take parameters.
43594361
* If there is one, return it, otherwise return the error tree.
43604362
*/
4361-
def tryParameterless(alts: List[TermRef])(error: => tpd.Tree): Tree =
4363+
def tryParameterless(error: => tpd.Tree): Tree =
43624364
alts.filter(_.info.isParameterless) match
43634365
case alt :: Nil => readaptSimplified(tree.withType(alt))
43644366
case _ =>
43654367
altDenots.find(_.info.paramInfoss == ListOfNil) match
4366-
case Some(alt) => readaptSimplified(tree.withType(alt.symbol.denot.termRef))
4368+
case Some(alt) => readaptSimplified(tree.withType(altRef(alt)))
43674369
case _ => error
43684370

4369-
def altRef(alt: SingleDenotation) = TermRef(ref.prefix, ref.name, alt)
4370-
val alts = altDenots.map(altRef)
4371-
43724371
resolveOverloaded(alts, pt) match
43734372
case alt :: Nil =>
43744373
readaptSimplified(tree.withType(alt))
@@ -4384,7 +4383,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43844383
// insert apply or convert qualifier, but only for a regular application
43854384
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
43864385
case _ =>
4387-
tryParameterless(alts)(errorNoMatch)
4386+
tryParameterless(errorNoMatch)
43884387
case ambiAlts =>
43894388
// If there are ambiguous alternatives, and:
43904389
// 1. the types aren't erroneous
@@ -4410,7 +4409,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
44104409
case _: FunProto =>
44114410
errorAmbiguous
44124411
case _ =>
4413-
tryParameterless(alts)(errorAmbiguous)
4412+
tryParameterless(errorAmbiguous)
44144413
end adaptOverloaded
44154414

44164415
def adaptToArgs(wtp: Type, pt: FunProto): Tree = wtp match {

tests/pos/i24631/TestJava.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package example;
2+
3+
public abstract class TestJava<T> {
4+
public abstract T create(String foo);
5+
6+
// Note that this is the method that's called from Scala code
7+
public T create() { return create(""); }
8+
9+
public static class Concrete extends TestJava<String> {
10+
@Override public String create(String foo) { return foo; }
11+
}
12+
}

tests/pos/i24631/test.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
val s = new example.TestJava.Concrete().create
2+
val s2: String = s

tests/pos/i24631b.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//> using options -source:3.0-migration
2+
3+
abstract class C[A]:
4+
def create(s: String): A
5+
def create(): A = create("")
6+
7+
class D extends C[String]:
8+
def create(s: String): String = s
9+
10+
val s = D().create
11+
val s2: String = s

0 commit comments

Comments
 (0)