Skip to content

Commit

Permalink
Merge pull request #14058 from dotty-staging/fix-13997
Browse files Browse the repository at this point in the history
Check variance of RHS of opaque type
  • Loading branch information
prolativ committed Dec 7, 2021
2 parents 80ec523 + 9d729c3 commit fc7e8c3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,8 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
else (tree.rhs, sym.info) match
case (rhs: LambdaTypeTree, bounds: TypeBounds) =>
VarianceChecker.checkLambda(rhs, bounds)
if sym.isOpaqueAlias then
VarianceChecker.checkLambda(rhs, TypeBounds.upper(sym.opaqueAlias))
case _ =>
processMemberDef(super.transform(tree))
case tree: New if isCheckable(tree) =>
Expand Down
10 changes: 10 additions & 0 deletions tests/neg/i13997.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
opaque type CovariantArray[+A] = Array[A] // error

object CovariantArray:
def crash() =
val stringArray: CovariantArray[String] = Array("foo", "bar")
val anyArray: CovariantArray[Any] = stringArray
anyArray(0) = 42
stringArray(0).length

@main def Test = CovariantArray.crash()

0 comments on commit fc7e8c3

Please sign in to comment.