question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Invariant opaque type refinement loss across external dependency

See original GitHub issue

Edit:

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:closed
  • Created 2 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
soronpocommented, Jul 20, 2021

@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.

# scala3-compiler src\main\scala\Main.scala                                                                             
# scala3-compiler src\test\scala\Test.scala                                                                             
-- Error: src\test\scala\Test.scala:3:33 -------------------------------------------------------------------------------
3 |  val fails = summon[x.Out =:= 7]                                                                                    
  |                                 ^                                                                                   
  |                                 Cannot prove that Test.x.Out =:= (7 : Int).                                         
1 error found                                                                                                           
0reactions
anatoliykmetyukcommented, Jul 20, 2021

Looks good!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found