Skip to content

Check variance of RHS of opaque type #14058

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()