Skip to content

@uncheckedVariance leaks into inferred types at use site #8988

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
smarter opened this issue May 16, 2020 · 3 comments
Closed

@uncheckedVariance leaks into inferred types at use site #8988

smarter opened this issue May 16, 2020 · 3 comments

Comments

@smarter
Copy link
Member

smarter commented May 16, 2020

scala> List(1)
val res0: List[Int] = List(1)

scala> res0.tail
val res1: List[Int @uncheckedVariance] = List()

We could drop @uncheckedVariance in asSeenFrom but that breaks overrides which rely on the inferred type coming from the overridden definition containing the annotation, for example https://github.com/lampepfl/dotty/blob/9450bf2c9725c3616743e9617844e6c55c86c67a/tests/run/CollectionTests.scala#L168

Maybe we can drop them when inferring a result type (that does not come from overriding something), in the same way we drop skolems: https://github.com/lampepfl/dotty/blob/9450bf2c9725c3616743e9617844e6c55c86c67a/compiler/src/dotty/tools/dotc/typer/Namer.scala#L1463 but that doesn't help with chained expressions

@smarter
Copy link
Member Author

smarter commented May 16, 2020

Even more concerning:

scala> List(1,2,3)
val res3: List[Int] = List(1, 2, 3)

scala> res3.tail
val res4: List[Int @uncheckedVariance] = List(2, 3)

scala> res4.tail
val res5: List[Int @uncheckedVariance @uncheckedVariance] = List(3)

scala> res5.tail
val res6: List[Int @uncheckedVariance @uncheckedVariance @uncheckedVariance] = List()

scala> List(1,2,3).tail.tail.tail
val res7: List[Int @uncheckedVariance @uncheckedVariance @uncheckedVariance] = List()

@odersky
Copy link
Contributor

odersky commented May 18, 2020

Maybe @uncheckedVariance should be an annotation on symbols instead.

@joroKr21
Copy link
Member

joroKr21 commented May 18, 2020

I recently learned that in Scala 2 @uncheckedVariance can be used on any type to prevent the variance check from descending deeper. But it feels more natural to associate the annotation with the type parameter. However that would not be backwards compatible.

    def impl2[G[_, _]] = new UncheckedHKT {
      type F[+A, -B] = G[A, B] @uncheckedVariance
    }

@smarter smarter added this to the 3.0.0-M1 milestone Sep 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants