Skip to content

Commit 76a056f

Browse files
committed
Refactor viewExists
Factor out isValueSubClass into separate method. Will probably come in handly elsewhere, and makes the code easier to understand.
1 parent c54debe commit 76a056f

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
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 `to`? */
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/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

0 commit comments

Comments
 (0)