ScalaMock icon indicating copy to clipboard operation
ScalaMock copied to clipboard

union / intersection type and generic class issue

Open migiside opened this issue 10 months ago • 3 comments

I found a similar issue to #514

ScalaMock Version (e.g. 3.5.0)

6.0.0

Scala Version (e.g. 2.12)

3.3.3

Runtime (JVM or JS)

Eclipse Adoptium Java 21.0.2

Please describe the expected behavior of the issue

It should compile.

Please provide a description of what actually happens

compile error

[error] 28 |    val m = mock[C1]
[error]    |                    ^
[error]    |                    Found:    (v : A & B[T])
[error]    |                    Required: A & B[T²]
[error]    |
[error]    |                    where:    T  is a type in method f
[error]    |                              T² is a type variable

[error] 33 |    val m = mock[C2]
[error]    |                    ^
[error]    |                    Found:    (v : B[T & A])
[error]    |                    Required: B[T² & A]
[error]    |
[error]    |                    where:    T  is a type in method f
[error]    |                              T² is a type variable

[error] 38 |    val m = mock[C3]
[error]    |                    ^
[error]    |                    Found:    (v : A | B[T])
[error]    |                    Required: A | B[T²]
[error]    |
[error]    |                    where:    T  is a type in method f
[error]    |                              T² is a type variable

[error] 43 |    val m = mock[C4]
[error]    |                    ^
[error]    |                    Found:    (v : B[T | A])
[error]    |                    Required: B[T² | A]
[error]    |
[error]    |                    where:    T  is a type in method f
[error]    |                              T² is a type variable

Reproducible Test Case

trait A

trait B[T]

trait C1 {
  def f[T](v: A & B[T]): Unit
}

trait C2 {
  def f[T](v: B[T & A]): Unit
}

trait C3 {
  def f[T](v: A | B[T]): Unit
}

trait C4 {
  def f[T](v: B[T | A]): Unit
}

class Test extends AsyncFunSuite with AsyncMockFactory {
  
  test("intersection 1") {
    val m = mock[C1]
    succeed
  }

  test("intersection 2") {
    val m = mock[C2]
    succeed
  }

  test("union 1") {
    val m = mock[C3]
    succeed
  }

  test("union 2") {
    val m = mock[C4]
    succeed
  }

}

migiside avatar Apr 08 '24 13:04 migiside

Hi again. Oh, this cases were on my mind, but I forgot about them. I'll fix it

goshacodes avatar Apr 11 '24 05:04 goshacodes

hi, that is typical. looking forward to the fix!

migiside avatar Apr 11 '24 12:04 migiside

There is a problem with one of the cases (The last one). I'm still looking for a solution

goshacodes avatar Apr 24 '24 14:04 goshacodes