File tree 5 files changed +50
-2
lines changed
compiler/src/dotty/tools/dotc
5 files changed +50
-2
lines changed Original file line number Diff line number Diff line change @@ -816,6 +816,8 @@ class Definitions {
816
816
def SetterMetaAnnot (implicit ctx : Context ): ClassSymbol = SetterMetaAnnotType .symbol.asClass
817
817
lazy val ShowAsInfixAnotType : TypeRef = ctx.requiredClassRef(" scala.annotation.showAsInfix" )
818
818
def ShowAsInfixAnnot (implicit ctx : Context ): ClassSymbol = ShowAsInfixAnotType .symbol.asClass
819
+ lazy val FunctionalInterfaceAnnotType = ctx.requiredClassRef(" java.lang.FunctionalInterface" )
820
+ def FunctionalInterfaceAnnot (implicit ctx : Context ) = FunctionalInterfaceAnnotType .symbol.asClass
819
821
820
822
// convenient one-parameter method types
821
823
def methOfAny (tp : Type ): MethodType = MethodType (List (AnyType ), tp)
Original file line number Diff line number Diff line change @@ -1517,7 +1517,17 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
1517
1517
narrowByTypes(alts, args, resultType)
1518
1518
1519
1519
case pt =>
1520
- alts filter (normalizedCompatible(_, pt))
1520
+ val noSam = alts filter (normalizedCompatible(_, pt))
1521
+ if (noSam.isEmpty) {
1522
+ pt match {
1523
+ case SAMType (mtp) =>
1524
+ val sam = narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
1525
+ if (sam.nonEmpty && ! pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot ))
1526
+ ctx.warning(ex " $pt does not have the @FunctionalInterface annotation. " , ctx.tree.pos)
1527
+ sam
1528
+ case _ => noSam
1529
+ }
1530
+ } else noSam
1521
1531
}
1522
1532
val found = narrowMostSpecific(candidates)
1523
1533
if (found.length <= 1 ) found
Original file line number Diff line number Diff line change @@ -3,7 +3,7 @@ import collection._
3
3
object Test {
4
4
def check (obj : AnyRef ): Unit = {
5
5
val bos = new ByteArrayOutputStream ()
6
- val out = new ObjectOutputStream (println) // error
6
+ val out = new ObjectOutputStream (println)
7
7
val arr = bos toByteArray ()
8
8
val in = (())
9
9
val deser = ()
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ var flag = false
3
+
4
+ def f (): Unit = assert(false )
5
+ def f (x : Int ): Unit = assert(false )
6
+ def f (x : String ): Unit = flag = true
7
+
8
+ def foo (c : java.util.function.Consumer [String ]) = c.accept(" " )
9
+
10
+ def main (args : Array [String ]) = {
11
+ foo(f)
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ var flag = false
3
+
4
+ def f (x : Int ): Unit = assert(false )
5
+ def f (x : String ): Unit = assert(false )
6
+ def f : java.io.OutputStream = new java.io.OutputStream {
7
+ def write (x : Int ) = ()
8
+ }
9
+
10
+ def g (x : Int ): Unit = flag = true
11
+ def g (x : String ): Unit = assert(false )
12
+
13
+ def main (args : Array [String ]) = {
14
+ val oosF = new java.io.ObjectOutputStream (f)
15
+ oosF.write(0 )
16
+ oosF.close()
17
+
18
+ val oosG = new java.io.ObjectOutputStream (g) // need warning
19
+ oosG.write(0 )
20
+ oosG.close()
21
+ assert(flag)
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments