Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler creates Infinite loop when define extension of opaque type which references to other opaque type #22393

Open
kazzna opened this issue Jan 17, 2025 · 1 comment
Labels
area:opaque-types area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug

Comments

@kazzna
Copy link

kazzna commented Jan 17, 2025

Compiler version

3.6.2

If you're not sure what version you're using, run print scalaVersion from sbt
(if you're running scalac manually, use scalac -version instead).

Minimized code

A.scala

case class A[AA](a: AA) {
  def map[B](f: AA => B): A[B] = A(f(a))
}

B.scala

opaque type B[X] = A[X]

object B {
  def apply[X](x: X): B[X] = A(x)
  
  extension [X](b: B[X])
    def map[C](f: X => C): B[C] = b.map(f)
}

C.scala

opaque type C[A] = B[A]

object C {
  def apply[A](a: A): C[A] = B(a)
  
  extension [A](c: C[A])
    def map[B](f: A => B): C[B] = c.map(f)
}

Output

[warn] 7 |    def map[B](f: A => B): C[B] = c.map(f)
[warn]   |                                  ^^^^^^^^
[warn]   |                                  Infinite loop in function body
[warn]   |                                  C.map[A](c)[B](f)

Expectation

Wish to be compiled as type B.

@kazzna kazzna added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 17, 2025
@kazzna kazzna changed the title Compiler creates Infinite loop when define extension of opaque type which wraps other opaque type Compiler creates Infinite loop when define extension of opaque type which references to other opaque type Jan 17, 2025
@kazzna
Copy link
Author

kazzna commented Jan 17, 2025

In my project, types are defined for almost all trivial things, such as LastName type for last name, etc.
Some types are referenced to a type in shared library, and recently shared library team decided to
change that type to opaque type for another type.
Then, this warn happens everywhere.

Is there any workarounds there?

@Gedochao Gedochao added area:reporting Error reporting including formatting, implicit suggestions, etc area:opaque-types and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:opaque-types area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug
Projects
None yet
Development

No branches or pull requests

2 participants