Skip to content
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

2.13.2: @uncheckedVariance is ignored in type member definitions #11968

Closed
neko-kai opened this issue Apr 29, 2020 · 5 comments · Fixed by scala/scala#8938
Closed

2.13.2: @uncheckedVariance is ignored in type member definitions #11968

neko-kai opened this issue Apr 29, 2020 · 5 comments · Fixed by scala/scala#8938
Assignees
Milestone

Comments

@neko-kai
Copy link

reproduction steps

To reproduce execute:

git clone https://github.com/7mind/izumi.git
cd izumi
git checkout bug/no-unchecked-variance
sbt compile

problem

Unchecked variance annotations are ignored and variance errors abort compilation:

[error] izumi/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/DIResource.scala:776:12: contravariant type RR occurs in invariant position in type [-RR, +EE, +AA]F0[RR @scala.annotation.unchecked.uncheckedVariance,EE @scala.annotation.unchecked.uncheckedVariance,AA @scala.annotation.unchecked.uncheckedVariance] of type F
[error]       type F[-RR, +EE, +AA] = F0[RR @v, EE @v, AA @v]
[error]            ^
[error] izumi/distage/distage-core-api/src/main/scala/izumi/distage/model/definition/DIResource.scala:801:12: contravariant type RR occurs in invariant position in type [-RR, +EE, +AA]F0[RR @scala.annotation.unchecked.uncheckedVariance,EE @scala.annotation.unchecked.uncheckedVariance,AA @scala.annotation.unchecked.uncheckedVariance] @scala.annotation.unchecked.uncheckedVariance of type F
[error]       type F[-RR, +EE, +AA] = F0[RR @v, EE @v, AA @v] @v
[error]            ^

Minimized example (https://scastie.scala-lang.org/NupT3nqjS6qGhHIIAYaA3A):

import scala.annotation.unchecked.uncheckedVariance

trait T {
  type F[+_]
}
object T {
  implicit def fromUnchecked[F0[_]]: T { type F[+A] = F0[A @uncheckedVariance] } = new T {
    type F[+A] = F0[A @uncheckedVariance]
  }
}
covariant type A occurs in invariant position in type [+A]F0[A @scala.annotation.unchecked.uncheckedVariance] of type F

expectation

Expected code to compile as in 2.13.1.

@neko-kai
Copy link
Author

Unchecked variance annotation was prompted by buggy implicit search involving variant higher-kinded types, the bug still persist in 2.13.2 so trying to remove uncheckedVariance didn't work:

git clone https://github.com/7mind/izumi.git
cd izumi
git checkout bug/variant-implicit-search
sbt distage-core/test:compile
[error] izumi/distage/distage-core/src/test/scala/izumi/distage/injector/ZIOHasInjectionTest.scala:163:49: could not find implicit ResourceTag for ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO]!
[error] could not find implicit value for Tag[ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO]]. Did you forget to put on a Tag, TagK or TagKK context bound on one of the parameters in ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO]? e.g. def x[T: Tag, F[_]: TagK] = ...
[error]
[error]
[error] <trace>:
[error]   deriving Tag for ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO], dealiased: ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO]:
[error]   succeeded for: ZIOHasInjectionTest.this.ResourceHasImpl[zio.ZIO]
[error]         make[Trait2].named("classbased").fromHas[ResourceHasImpl[ZIO]]
[error]                                                 ^
[error] izumi/distage/distage-core/src/test/scala/izumi/distage/injector/ZIOHasInjectionTest.scala:222:29: could not find implicit ResourceTag for ZIOHasInjectionTest.this.ResourceHasImpl[F]!
[error] could not find implicit value for Tag[ZIOHasInjectionTest.this.ResourceHasImpl[F]]. Did you forget to put on a Tag, TagK or TagKK context bound on one of the parameters in ZIOHasInjectionTest.this.ResourceHasImpl[F]? e.g. def x[T: Tag, F[_]: TagK] = ...
[error]
[error]
[error] <trace>:
[error]   deriving Tag for ZIOHasInjectionTest.this.ResourceHasImpl[F], dealiased: ZIOHasInjectionTest.this.ResourceHasImpl[F]:
[error]   succeeded for: ZIOHasInjectionTest.this.ResourceHasImpl[F]
[error]         make[Trait2].fromHas[ResourceHasImpl[F]]
[error]                             ^
[error] two errors found

I can't seem to find any workaround to compile this code under 2.13.2

@SethTisue SethTisue added this to the 2.13.3 milestone Apr 29, 2020
@joroKr21
Copy link
Member

I didn't know you can use @uncheckedVariance like that

@joroKr21
Copy link
Member

joroKr21 commented Apr 29, 2020

@neko-kai can you open another issue for the implicit search problem?
Is it fixed in Dotty?

@neko-kai
Copy link
Author

will do

neko-kai added a commit to 7mind/izumi that referenced this issue Apr 30, 2020
…impossible to compile the project on that version
@neko-kai
Copy link
Author

@joroKr21 Posted - #11970, yes, it's fixed in Dotty.

@dwijnand dwijnand assigned joroKr21 and unassigned neko-kai May 4, 2020
neko-kai added a commit to 7mind/izumi that referenced this issue May 11, 2020
…impossible to compile the project on that version
neko-kai added a commit to 7mind/izumi that referenced this issue May 11, 2020
* Update to Scala 2.13.2, replace silencer @silent with @scala.annotation.nowarn

* Get rid of warnings

* postpone updating to 2.13.2 due to bug scala/bug#11968 that makes it impossible to compile the project on that version

* Fallback to `@silent` instead of `@nowarn` and silencer-1.6.0 due to ghik/silencer#53

* fix build

* fix build

* fix 2.12 build

* fix 2.12 build

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

Successfully merging a pull request may close this issue.

3 participants