File tree Expand file tree Collapse file tree 4 files changed +64
-7
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 4 files changed +64
-7
lines changed Original file line number Diff line number Diff line change @@ -4274,16 +4274,15 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4274
4274
typr.println(i " adapt overloaded $ref with alternatives ${altDenots map (_.info)}% \n\n % " )
4275
4275
4276
4276
/** Search for an alternative that does not take parameters.
4277
- * If there is one, return it, otherwise emit an error.
4277
+ * If there is one, return it, otherwise return the error tree .
4278
4278
*/
4279
4279
def tryParameterless (alts : List [TermRef ])(error : => tpd.Tree ): Tree =
4280
4280
alts.filter(_.info.isParameterless) match
4281
- case alt :: Nil => readaptSimplified(tree.withType(alt))
4282
- case _ =>
4283
- if altDenots.exists(_.info.paramInfoss == ListOfNil ) then
4284
- typed(untpd.Apply (untpd.TypedSplice (tree), Nil ), pt, locked)
4285
- else
4286
- error
4281
+ case alt :: Nil => readaptSimplified(tree.withType(alt))
4282
+ case _ =>
4283
+ altDenots.find(_.info.paramInfoss == ListOfNil ) match
4284
+ case Some (alt) => readaptSimplified(tree.withType(alt.symbol.denot.termRef))
4285
+ case _ => error
4287
4286
4288
4287
def altRef (alt : SingleDenotation ) = TermRef (ref.prefix, ref.name, alt)
4289
4288
val alts = altDenots.map(altRef)
@@ -4976,6 +4975,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
4976
4975
case _ => NoType
4977
4976
case _ => NoType
4978
4977
4978
+ // begin adapt1
4979
4979
tree match {
4980
4980
case _ : MemberDef | _ : PackageDef | _ : Import | _ : WithoutTypeOrPos [? ] | _ : Closure => tree
4981
4981
case _ => tree.tpe.widen match {
Original file line number Diff line number Diff line change
1
+
2
+ abstract class P {
3
+ def foo1 (): Int = 1
4
+ def foo2 (x : Int ): Int = 22
5
+ def g4 (s : String ): String = s * 4
6
+ }
7
+
8
+ class C extends P {
9
+ def foo1 (x : Int ): Int = 11
10
+ def foo2 (): Int = 2
11
+
12
+ def foo3 (): Int = 3
13
+ def foo3 (x : Int ): Int = 33
14
+
15
+ def g4 (): Int = 4
16
+ }
17
+
18
+ object Test extends App {
19
+ val c = new C
20
+ println(c.foo1) // error was omitted because of nullary fallback during ambiguous overload resolution
21
+ println(c.foo2) // error, add parens
22
+ println(c.foo3) // error
23
+ println(c.g4) // error
24
+ val s : String = c.g4 // error missing arg, expected type picks method
25
+ println(s)
26
+ }
27
+
28
+ /* Scala 2 warns for all three selections:
29
+ warning: Auto-application to `()` is deprecated. Supply the empty argument list `()` explicitly to invoke method foo1,
30
+ or remove the empty argument list from its definition (Java-defined methods are exempt).
31
+ In Scala 3, an unapplied method like this will be eta-expanded into a function. [quickfixable]
32
+ */
Original file line number Diff line number Diff line change
1
+
2
+ interface I {
3
+ default int f () { return 42 ; }
4
+ }
5
+
6
+ public class Over implements I {
7
+ public int f (int i ) { return 42 + i ; }
8
+ }
Original file line number Diff line number Diff line change
1
+ //> using options -source:3.0-migration
2
+
3
+ // Hope to see a migration warning! with quickfix.
4
+
5
+ class P {
6
+ def g (): Int = 42
7
+ }
8
+ class C extends P {
9
+ def g (i : Int ): Int = 42 + i
10
+ }
11
+
12
+ object Test extends App {
13
+ val over = Over ()
14
+ println(over.f) // nowarn Java
15
+ val c = C ()
16
+ println(c.g) // warn migration
17
+ }
You can’t perform that action at this time.
0 commit comments