Skip to content

generic tuple not of subtype of ProductN #15253

Open
@m8nmueller

Description

@m8nmueller

Compiler version

3.1.2

Minimized code

case class Foo(a: Int, b: String)
val foo = Foo(1, "Hello")
var x: Tuple2[Int, String] = Tuple.fromProductTyped(foo)
var y: Product2[Int, String] = x
var z: Product2[Int, String] = Tuple.fromProductTyped(foo)

Output

-- [E007] Type Mismatch Error: -------------------------------------------------
5 |var z: Product2[Int, String] = Tuple.fromProductTyped(foo)
  |                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |                               Found:    (Int, String)
  |                               Required: Product2[Int, String]

Explanation
===========

Tree: Tuple.fromProductTyped[Foo](foo)(
  Foo.$asInstanceOf[
    
      (
        deriving.Mirror.Product{
          MirroredType = Foo; MirroredMonoType = Foo; MirroredElemTypes <: Tuple
        }
       & 
        scala.deriving.Mirror.Product{
          MirroredMonoType = Foo; MirroredType = Foo; 
            MirroredLabel = ("Foo" : String)
        }
      ){
        MirroredElemTypes = (Int, String); 
          MirroredElemLabels = (("a" : String), ("b" : String))
      }
    
  ]
)

I tried to show that
  (Int, String)
conforms to
  Product2[Int, String]
but the comparison trace ended with `false`:
          
  ==> (Int, String)  <:  Product2[Int, String]
  <== (Int, String)  <:  Product2[Int, String] = false

The tests were made under the empty constraint

Expectation

As (A, B) = Tuple2[A, B] is a direct subclass of Product2[Int, String], I would expect that the assignment to z compiles.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions