paulbutcher / ScalaMock

Native Scala mocking framework
http://scalamock.org/
MIT License
501 stars 98 forks source link

union / intersection type and generic class issue #516

Closed migiside closed 1 month ago

migiside commented 3 months ago

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
  }

}
goshacodes commented 3 months ago

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

migiside commented 3 months ago

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

goshacodes commented 2 months ago

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