File tree 1 file changed +11
-3
lines changed
compiler/src/dotty/tools/dotc/core
1 file changed +11
-3
lines changed Original file line number Diff line number Diff line change @@ -1098,10 +1098,18 @@ object Types {
1098
1098
* def o: Outer
1099
1099
* <o.x.type>.widen = o.C
1100
1100
*/
1101
- final def widen (using Context ): Type = widenSingleton match {
1101
+ final def widen (using Context ): Type = this match
1102
+ case _ : TypeRef | _ : MethodOrPoly => this // fast path for most frequent cases
1103
+ case tp : TermRef => // fast path for next most frequent case
1104
+ if tp.isOverloaded then tp else tp.underlying.widen
1105
+ case tp : SingletonType => tp.underlying.widen
1102
1106
case tp : ExprType => tp.resultType.widen
1103
- case tp => tp
1104
- }
1107
+ case tp =>
1108
+ val tp1 = tp.stripTypeVar.stripAnnots
1109
+ if tp1 eq tp then tp
1110
+ else
1111
+ val tp2 = tp1.widen
1112
+ if tp2 ne tp1 then tp2 else tp
1105
1113
1106
1114
/** Widen from singleton type to its underlying non-singleton
1107
1115
* base type by applying one or more `underlying` dereferences.
You can’t perform that action at this time.
0 commit comments