File tree 3 files changed +13
-5
lines changed
compiler/src/dotty/tools/dotc
3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ object TypeOps:
164
164
// corrective steps, so no widening is wanted.
165
165
simplify(l, theMap) | simplify(r, theMap)
166
166
case AnnotatedType (parent, annot)
167
- if ! ctx.mode.is(Mode .Type ) && annot.symbol == defn. UncheckedVarianceAnnot =>
167
+ if annot.symbol == defn. UncheckedVarianceAnnot && ! ctx.mode.is(Mode .Type ) && ! theMap. isInstanceOf [ SimplifyKeepUnchecked ] =>
168
168
simplify(parent, theMap)
169
169
case _ : MatchType =>
170
170
val normed = tp.tryNormalize
@@ -180,6 +180,8 @@ object TypeOps:
180
180
def apply (tp : Type ): Type = simplify(tp, this )
181
181
}
182
182
183
+ class SimplifyKeepUnchecked (using Context ) extends SimplifyMap
184
+
183
185
/** Approximate union type by intersection of its dominators.
184
186
* That is, replace a union type Tn | ... | Tn
185
187
* by the smallest intersection type of base-class instances of T1,...,Tn.
Original file line number Diff line number Diff line change @@ -1550,10 +1550,12 @@ class Namer { typer: Typer =>
1550
1550
// For justification on the use of `@uncheckedVariance`, see
1551
1551
// `default-getter-variance.scala`.
1552
1552
AnnotatedType (defaultTp, Annotation (defn.UncheckedVarianceAnnot ))
1553
- else tp.widenTermRefExpr.simplified match
1554
- case ctp : ConstantType if isInlineVal => ctp
1555
- case tp =>
1556
- TypeComparer .widenInferred(tp, pt)
1553
+ else
1554
+ // don't strip @uncheckedVariance annot for default getters
1555
+ TypeOps .simplify(tp.widenTermRefExpr,
1556
+ if defaultTp.exists then TypeOps .SimplifyKeepUnchecked () else null ) match
1557
+ case ctp : ConstantType if isInlineVal => ctp
1558
+ case tp => TypeComparer .widenInferred(tp, pt)
1557
1559
1558
1560
// Replace aliases to Unit by Unit itself. If we leave the alias in
1559
1561
// it would be erased to BoxedUnit.
Original file line number Diff line number Diff line change
1
+ import scala .annotation .unchecked .uncheckedVariance
2
+
3
+ final case class Outlet [T ](out : T )
4
+ final case class SourceShape [+ T ](val out : Outlet [T @ uncheckedVariance])
You can’t perform that action at this time.
0 commit comments