Skip to content

Commit 3b1e506

Browse files
som-snyttWojciechMazur
authored andcommitted
Construct ref more correctly
[Cherry-picked 14909dd]
1 parent fc4dc3b commit 3b1e506

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
@@ -4288,23 +4288,22 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
42884288
val allDenots = ref.denot.alternatives
42894289
if pt.isExtensionApplyProto then allDenots.filter(_.symbol.is(ExtensionMethod))
42904290
else allDenots
4291+
def altRef(alt: SingleDenotation) = TermRef(ref.prefix, ref.name, alt)
4292+
val alts = altDenots.map(altRef)
42914293

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

42944296
/** Search for an alternative that does not take parameters.
42954297
* If there is one, return it, otherwise return the error tree.
42964298
*/
4297-
def tryParameterless(alts: List[TermRef])(error: => tpd.Tree): Tree =
4299+
def tryParameterless(error: => tpd.Tree): Tree =
42984300
alts.filter(_.info.isParameterless) match
42994301
case alt :: Nil => readaptSimplified(tree.withType(alt))
43004302
case _ =>
43014303
altDenots.find(_.info.paramInfoss == ListOfNil) match
4302-
case Some(alt) => readaptSimplified(tree.withType(alt.symbol.denot.termRef))
4304+
case Some(alt) => readaptSimplified(tree.withType(altRef(alt)))
43034305
case _ => error
43044306

4305-
def altRef(alt: SingleDenotation) = TermRef(ref.prefix, ref.name, alt)
4306-
val alts = altDenots.map(altRef)
4307-
43084307
resolveOverloaded(alts, pt) match
43094308
case alt :: Nil =>
43104309
readaptSimplified(tree.withType(alt))
@@ -4320,7 +4319,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43204319
// insert apply or convert qualifier, but only for a regular application
43214320
tryInsertApplyOrImplicit(tree, pt, locked)(errorNoMatch)
43224321
case _ =>
4323-
tryParameterless(alts)(errorNoMatch)
4322+
tryParameterless(errorNoMatch)
43244323
case ambiAlts =>
43254324
// If there are ambiguous alternatives, and:
43264325
// 1. the types aren't erroneous
@@ -4346,7 +4345,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
43464345
case _: FunProto =>
43474346
errorAmbiguous
43484347
case _ =>
4349-
tryParameterless(alts)(errorAmbiguous)
4348+
tryParameterless(errorAmbiguous)
43504349
end adaptOverloaded
43514350

43524351
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)