Skip to content

Commit a654d20

Browse files
committed
Merge pull request #674 from dotty-staging/fix/#655-eta-expansion
Fix/#655 eta expansion
2 parents bb75d40 + 0c60f21 commit a654d20

File tree

5 files changed

+19
-17
lines changed

5 files changed

+19
-17
lines changed

src/dotty/tools/dotc/core/Types.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -601,6 +601,19 @@ object Types {
601601
ctx.typeComparer.isSameType(this, that)
602602
}
603603

604+
/** Is this type a primitive value type which can be widened to the primitive value type `that`? */
605+
def isValueSubType(that: Type)(implicit ctx: Context) = widenExpr match {
606+
case self: TypeRef if defn.ScalaValueClasses contains self.symbol =>
607+
that.widenExpr match {
608+
case that: TypeRef if defn.ScalaValueClasses contains that.symbol =>
609+
defn.isValueSubClass(self.symbol, that.symbol)
610+
case _ =>
611+
false
612+
}
613+
case _ =>
614+
false
615+
}
616+
604617
/** Is this type a legal type for a member that overrides another
605618
* member of type `that`? This is the same as `<:<`, except that
606619
* the types ()T and => T are identified, and T is seen as overriding

src/dotty/tools/dotc/typer/EtaExpansion.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ object EtaExpansion {
5757
/** Lift arguments that are not-idempotent into ValDefs in buffer `defs`
5858
* and replace by the idents of so created ValDefs.
5959
*/
60-
def liftArgs(defs: mutable.ListBuffer[Tree], methType: Type, args: List[Tree])(implicit ctx: Context) =
61-
methType match {
60+
def liftArgs(defs: mutable.ListBuffer[Tree], methRef: Type, args: List[Tree])(implicit ctx: Context) =
61+
methRef.widen match {
6262
case MethodType(paramNames, paramTypes) =>
6363
(args, paramNames, paramTypes).zipped map { (arg, name, tp) =>
6464
if (tp.isInstanceOf[ExprType]) arg

src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,10 @@ trait Implicits { self: Typer =>
382382
&& !to.isError
383383
&& !ctx.isAfterTyper
384384
&& (ctx.mode is Mode.ImplicitsEnabled)
385-
&& { from.widenExpr match {
386-
case from: TypeRef if defn.ScalaValueClasses contains from.symbol =>
387-
to.widenExpr match {
388-
case to: TypeRef if defn.ScalaValueClasses contains to.symbol =>
389-
util.Stats.record("isValueSubClass")
390-
return defn.isValueSubClass(from.symbol, to.symbol)
391-
case _ =>
392-
}
393-
case from: ValueType =>
394-
;
395-
case _ =>
396-
return false
397-
}
398-
inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess]
399-
}
385+
&& from.isInstanceOf[ValueType]
386+
&& ( from.isValueSubType(to)
387+
|| inferView(dummyTreeOfType(from), to)(ctx.fresh.setExploreTyperState).isInstanceOf[SearchSuccess]
388+
)
400389
)
401390

402391
/** Find an implicit conversion to apply to given tree `from` so that the
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)