Invariant opaque type refinement loss across external dependency
See original GitHub issueEdit:
I managed to further minimize the example.
It seems that type inference behaves differently across test dependency and fails to reduce (possibly any kind of different module dependency is affected).
Compiler version
v3.0.1-RC2 (also checked on nightly 3.0.2-RC1-bin-20210624-ecbe3d2-NIGHTLY)
Minimized code
Minimized project at: https://github.com/soronpo/dottybug/tree/invariance_widen_err
Main.scala
opaque type Lie[W <: Int] = Int
object Lie:
trait TC[-T]:
type Out
object TC:
given [W <: Int]: TC[Lie[W]] with
type Out = W
val x = summon[Lie.TC[Lie[7]]]
val works = summon[x.Out =:= 7]
Test.scala //must be placed at scala/test
object Test:
val x = summon[Lie.TC[Lie[7]]]
val fails = summon[x.Out =:= 7]
Output
[error] -- Error: C:\IdeaProjects\dottybug\src\test\scala\Test.scala:3:33
[error] 3 | val fails = summon[x.Out =:= 7]
[error] | ^
[error] | Cannot prove that Test.x.Out =:= (7 : Int).
[error] one error found
Expectation
No error. Notice the same expression works within the main module and fails within the test module.
Note
Opaque types seem to be part of the problem, since if we change Lie
to a trait the error goes away.
The contravariance in Lie.TC
is also crucial for the error, but it should not cause widening because Lie
is invariant.
Issue Analytics
- State:
- Created 2 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Dafny Reference Manual
traits, inductive and co-inductive datatypes, new_types, type synonyms, opaque types, and iterators) and modules, where the order of ...
Read more >Backward-Bounded DSE: Targeting Infeasibility Questions on ...
e.g., detecting protection schemes such as opaque predicates, fall into the category of infeasibility questions. We present Backward-.
Read more >Practical Refinement-Type Checking
This approach builds on the strength of the type system of a language by adding the ability to specify refinements of each type....
Read more >Types for Modules - Microsoft
corresponds to existential quantification over types. In contrast to previous accounts, our analysis does not involve first-order dependent types.
Read more >Dafny Reference Manual
Specifications describe logical properties of Dafny methods, functions, lambdas, iterators and loops. They specify preconditions, postconditions, invariants, ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@anatoliykmetyuk I further minimized the example. See updated OP. I also verified that when running the compilation manually via
scala3-compiler
, I still get the error.Looks good!