Skip to content

type aliases leak underlying opaque types through separate compilation #13377

Closed
@soronpo

Description

@soronpo

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions