type aliases leak underlying opaque types through separate compilation
See original GitHub issueMatch 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:
- Created 2 years ago
- Comments:7 (4 by maintainers)
Top 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 >
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
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.
@odersky Do you know what’s different in the model between the separate and the joint compilation scenarios?