Skip to content

Commit 0cc60eb

Browse files
committed
Simplifications
1 parent 6fb6680 commit 0cc60eb

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ object Applications {
174174
def productArity: Int = app.productArity
175175
def productElement(n: Int): Any = app.productElement(n)
176176
}
177-
177+
178178
/** The unapply method of this extractor also recognizes ExtMethodApplys in closure blocks.
179179
* This is necessary to deal with closures as left arguments of extension method applications.
180180
* A test case is i5606.scala
@@ -1511,14 +1511,14 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15111511

15121512
case pt @ PolyProto(targs1, pt1) if targs.isEmpty =>
15131513
val alts1 = alts filter pt.isMatchedBy
1514-
resolveOverloaded(alts1, pt1, targs1.tpes, pos)
1514+
resolveOverloaded(alts1, pt1, targs1.tpes)
15151515

15161516
case defn.FunctionOf(args, resultType, _, _) =>
15171517
narrowByTypes(alts, args, resultType)
15181518

15191519
case pt =>
1520-
val noSam = alts filter (normalizedCompatible(_, pt))
1521-
if (noSam.isEmpty) {
1520+
val compat = alts.filter(normalizedCompatible(_, pt))
1521+
if (compat.isEmpty)
15221522
/*
15231523
* the case should not be moved to the enclosing match
15241524
* since SAM type must be considered only if there are no candidates
@@ -1528,14 +1528,10 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15281528
* new java.io.ObjectOutputStream(f)
15291529
*/
15301530
pt match {
1531-
case SAMType(mtp) =>
1532-
val sam = narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
1533-
if (sam.nonEmpty && !pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot))
1534-
ctx.warning(ex"${sam.head.designator} is eta-expanded even though $pt does not have the @FunctionalInterface annotation.", pos)
1535-
sam
1536-
case _ => noSam
1531+
case SAMType(mtp) => narrowByTypes(alts, mtp.paramInfos, mtp.resultType)
1532+
case _ => compat
15371533
}
1538-
} else noSam
1534+
else compat
15391535
}
15401536
val found = narrowMostSpecific(candidates)
15411537
if (found.length <= 1) found
@@ -1544,7 +1540,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
15441540
if (noDefaults.length == 1) noDefaults // return unique alternative without default parameters if it exists
15451541
else {
15461542
val deepPt = pt.deepenProto
1547-
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs, pos)
1543+
if (deepPt ne pt) resolveOverloaded(alts, deepPt, targs)
15481544
else alts
15491545
}
15501546
}

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2481,10 +2481,12 @@ class Typer extends Namer
24812481
!tree.symbol.is(InlineMethod) &&
24822482
!ctx.mode.is(Mode.Pattern) &&
24832483
!(isSyntheticApply(tree) && !isExpandableApply)) {
2484-
if (!pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot) &&
2485-
!defn.isFunctionType(pt) &&
2486-
SAMType.unapply(pt).isDefined)
2487-
ctx.warning(ex"${tree.symbol} is eta-expanded even though ${pt.classSymbol} does not have the @FunctionalInterface annotation.", tree.pos)
2484+
if (!defn.isFunctionType(pt))
2485+
pt match {
2486+
case SAMType(_) if !pt.classSymbol.hasAnnotation(defn.FunctionalInterfaceAnnot) =>
2487+
ctx.warning(ex"${tree.symbol} is eta-expanded even though $pt does not have the @FunctionalInterface annotation.", tree.pos)
2488+
case _ =>
2489+
}
24882490
simplify(typed(etaExpand(tree, wtp, arity), pt), pt, locked)
24892491
} else if (wtp.paramInfos.isEmpty && isAutoApplied(tree.symbol))
24902492
readaptSimplified(tpd.Apply(tree, Nil))

0 commit comments

Comments
 (0)