-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #2973: Check variances of class parents #4057
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -93,8 +93,8 @@ class VarianceChecker()(implicit ctx: Context) { | |
this(status, tp.resultType) // params will be checked in their TypeDef or ValDef nodes. | ||
case AnnotatedType(_, annot) if annot.symbol == defn.UncheckedVarianceAnnot => | ||
status | ||
//case tp: ClassInfo => | ||
// ??? not clear what to do here yet. presumably, it's all checked at local typedefs | ||
case tp: ClassInfo => | ||
foldOver(status, tp.classParents) | ||
case _ => | ||
foldOver(status, tp) | ||
} | ||
|
@@ -132,14 +132,16 @@ class VarianceChecker()(implicit ctx: Context) { | |
ctx.debuglog(s"Skipping variance check of ${sym.showDcl}") | ||
case tree: TypeDef => | ||
checkVariance(sym, tree.pos) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On |
||
tree.rhs match { | ||
case rhs: Template => traverseChildren(rhs) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here |
||
case _ => | ||
} | ||
case tree: ValDef => | ||
checkVariance(sym, tree.pos) | ||
case DefDef(_, tparams, vparamss, _, _) => | ||
checkVariance(sym, tree.pos) | ||
tparams foreach traverse | ||
vparamss foreach (_ foreach traverse) | ||
case Template(_, _, _, body) => | ||
traverseChildren(tree) | ||
case _ => | ||
} | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Foo[U] | ||
class Bar[-T] extends Foo[T] // error: contravariant type T occurs in invariant position |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This visit sees the parent classes, but stripped of any annotations!