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.

type aliases leak underlying opaque types through separate compilation

See original GitHub issue

Match types defined in the scope of an opaque definition leak the underlying opaque type if used in separate compilation module. Note: could be related to https://github.com/lampepfl/dotty/issues/12944

Compiler version

v3.0.2-RC2

Minimized code

See minimized branch at: https://github.com/soronpo/dottybug/tree/match_type_opaque_leak

main/scala/core/Foo.scala

package core

opaque type Foo <: Int = Int
type LeakFoo[M] = M match
  case _ => Foo

main/scala/LeakFoo.scala

type LeakFoo[M] = core.LeakFoo[M]

val works = summon[LeakFoo[Any] =:= core.Foo]

test/scala/Foo.scala

val shouldFail: LeakFoo[Any] = 1
val shouldWork = summon[LeakFoo[Any] =:= core.Foo]

Output

[error] -- Error: IdeaProjects\dottybug\src\test\scala\Foo.scala:2:50 --
[error] 2 |val shouldWork = summon[LeakFoo[Any] =:= core.Foo]
[error]   |                                                  ^
[error]   |                      Cannot prove that core.Foo$package.Foo =:= core.Foo.
[error] one error found

Expectation

shouldFail should generate a type-mismatch error shouldWork should compile fine.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
oderskycommented, Aug 29, 2021

I could track it down to a difference in the way package objects were inserted when typechecking source and unpickling. The unpickling version was faulty.

0reactions
dwijnandcommented, Aug 28, 2021

@odersky Do you know what’s different in the model between the separate and the joint compilation scenarios?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Strongly-typed type aliases · Issue #58 · dotnet/roslyn - GitHub
I would love to see strongly-typed type aliases in the C# programming ... as distinct types from the original type during compilation time....
Read more >
Opaque Type Aliases: More Details - Scala 3 - EPFL
Opaque type aliases must be members of classes, traits, or objects, or they are defined at the top-level. They cannot be defined in...
Read more >
Opaque result types - Pitches - Swift Forums
This proposal introduces an opaque type that can be used to describe an opaque result type for a function. opaque types can only...
Read more >
Advanced Types in Elm - Opaque Types - Charlie Koster
The constructor function for SortedLabels is not exposed in the module definition. That type is opaque. Instead, ascendingLabels and descendingLabels are ...
Read more >
Types: Type Aliases - HHVM and Hack Documentation
An alias created using newtype (such as Point above) is an opaque type alias. ... distinct from its underlying type and from any...
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