Skip to content

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

Closed
wants to merge 1 commit into from

Conversation

Blaisorblade
Copy link
Contributor

I'm opening this PR to recover this "lost" fix to a soundness issue (#2973, #3856). Let's see its status.

@Blaisorblade Blaisorblade self-assigned this Mar 1, 2018
@Blaisorblade
Copy link
Contributor Author

All failures (in test_legacy and test) have to do with tests/pos/Iterable.scala, in particular because type param CC is covariant for IterableCompanion but invariant for IterableImpls, yet IterableCompanion extends IterableImpls. The extension is annotated with @uncheckedVariance, so I guess I must only adapt the fix to respect @uncheckedVariance.

abstract class IterableCompanion[+CC[X] <: Iterable[X] with Collection[CC, X]] extends CollectionCompanion[CC] with IterableImpls[CC] @uncheckedVariance {

Copy link
Contributor Author

@Blaisorblade Blaisorblade left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guess I learned a bit about why this change is annoyingly hard. Trying to comment out some of the calls involved in the spurious error also removes the correct error from the new test.

@@ -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)
tree.rhs match {
case rhs: Template => traverseChildren(rhs)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here traverseChildren sees parents (in the form of a constructor call), but this Traverser ignores terms and only looks at definitions...

//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)
Copy link
Contributor Author

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!

@@ -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)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On tests/pos/Iterable.scala we get an error inside this call (going through tp.classParents), because sym contains the parens but without annotations!

@Blaisorblade Blaisorblade removed their assignment Mar 1, 2018
@Blaisorblade
Copy link
Contributor Author

Closing since this is likely noise — I've a first guess why Martin got stuck on it, and it's not an issue for a beginner like me yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants