Skip to content

Commit 0d481d5

Browse files
Medowhillodersky
authored andcommitted
fix test, change val name, & change warning point
1 parent b77c21d commit 0d481d5

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
13641364
* Two trials: First, without implicits or SAM conversions enabled. Then,
13651365
* if the fist finds no eligible candidates, with implicits and SAM conversions enabled.
13661366
*/
1367-
def resolveOverloaded(alts: List[TermRef], pt: Type, pos: Position = NoPosition)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
1367+
def resolveOverloaded(alts: List[TermRef], pt: Type)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
13681368

13691369
/** Is `alt` a method or polytype whose result type after the first value parameter
13701370
* section conforms to the expected type `resultType`? If `resultType`
@@ -1409,9 +1409,9 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
14091409
case _ => chosen
14101410
}
14111411

1412-
var found = resolveOverloaded(alts, pt, Nil, pos)(ctx.retractMode(Mode.ImplicitsEnabled))
1412+
var found = resolveOverloaded(alts, pt, Nil)(ctx.retractMode(Mode.ImplicitsEnabled))
14131413
if (found.isEmpty && ctx.mode.is(Mode.ImplicitsEnabled))
1414-
found = resolveOverloaded(alts, pt, Nil, pos)
1414+
found = resolveOverloaded(alts, pt, Nil)
14151415
found match {
14161416
case alt :: Nil => adaptByResult(alt) :: Nil
14171417
case _ => found
@@ -1423,7 +1423,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
14231423
* called twice from the public `resolveOverloaded` method, once with
14241424
* implicits and SAM conversions enabled, and once without.
14251425
*/
1426-
private def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type], pos: Position)(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
1426+
private def resolveOverloaded(alts: List[TermRef], pt: Type, targs: List[Type])(implicit ctx: Context): List[TermRef] = track("resolveOverloaded") {
14271427

14281428
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
14291429

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2268,7 +2268,7 @@ class Typer extends Namer
22682268
val altDenots = ref.denot.alternatives
22692269
typr.println(i"adapt overloaded $ref with alternatives ${altDenots map (_.info)}%, %")
22702270
val alts = altDenots.map(TermRef(ref.prefix, ref.name, _))
2271-
resolveOverloaded(alts, pt, tree.pos) match {
2271+
resolveOverloaded(alts, pt) match {
22722272
case alt :: Nil =>
22732273
readaptSimplified(tree.withType(alt))
22742274
case Nil =>
@@ -2480,9 +2480,11 @@ class Typer extends Namer
24802480
!tree.symbol.isConstructor &&
24812481
!tree.symbol.is(InlineMethod) &&
24822482
!ctx.mode.is(Mode.Pattern) &&
2483-
!(isSyntheticApply(tree) && !isExpandableApply))
2483+
!(isSyntheticApply(tree) && !isExpandableApply)) {
2484+
if (!pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot))
2485+
ctx.warning(ex"${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation.", tree.pos)
24842486
simplify(typed(etaExpand(tree, wtp, arity), pt), pt, locked)
2485-
else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
2487+
} else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
24862488
readaptSimplified(tpd.Apply(tree, Nil))
24872489
else if (wtp.isImplicitMethod)
24882490
err.typeMismatch(tree, pt)
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
object Test {
2-
def foo(c: java.util.function.Consumer[String]) = c.accept("")
3-
4-
def f(x: String): Unit = ()
2+
def foo(c: java.util.function.Consumer[Integer]) = c.accept(0)
53
def f(x: Int): Unit = ()
64

75
def main(args: Array[String]) = {
86
foo(f) // Ok: Consumer is @FunctionalInterface
9-
10-
val oos = new java.io.ObjectOutputStream(f) // error: OutputStream is not @FunctionalInterface
11-
oos.write(0)
12-
oos.close()
7+
new java.io.ObjectOutputStream(f) // error: OutputStream is not @FunctionalInterface
138
}
149
}

0 commit comments

Comments
 (0)