File tree Expand file tree Collapse file tree 3 files changed +13
-5
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -164,7 +164,7 @@ object TypeOps:
164164 // corrective steps, so no widening is wanted.
165165 simplify(l, theMap) | simplify(r, theMap)
166166 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 ] =>
168168 simplify(parent, theMap)
169169 case _ : MatchType =>
170170 val normed = tp.tryNormalize
@@ -180,6 +180,8 @@ object TypeOps:
180180 def apply (tp : Type ): Type = simplify(tp, this )
181181 }
182182
183+ class SimplifyKeepUnchecked (using Context ) extends SimplifyMap
184+
183185 /** Approximate union type by intersection of its dominators.
184186 * That is, replace a union type Tn | ... | Tn
185187 * 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 =>
15501550 // For justification on the use of `@uncheckedVariance`, see
15511551 // `default-getter-variance.scala`.
15521552 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)
15571559
15581560 // Replace aliases to Unit by Unit itself. If we leave the alias in
15591561 // 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