scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.84k stars 1.05k forks source link

Type equivalence of Tuple fails when x.type is used #10766

Closed hmf closed 3 years ago

hmf commented 3 years ago

Minimized code

    val t40: (Int, Int, Int) = (1,2,3)
    summon[(Int,Int,Int) =:= (Int,Int,Int)]
    summon[(Int,Int,Int) <:< (Int,Int,Int)]
    summon[t40.type <:< (Int,Int,Int)] 
    summon[tp6.type =:= tp6.type]
    summon[tp10.type =:= (Int,Int,Int)] // fail
    summon[(Int,Int,Int) =:= tp10.type] // fail
    summon[(Int,Int,Int) <:< tp10.type] // fail

Output

[error] 635 |    summon[tp10.type =:= (Int,Int,Int)] // fail
[error]     |                                       ^
[error]     | Cannot prove that (tp10 : (Int, Double, String)) =:= (Int, Int, Int).
[error] -- Error: /home/user/IdeaProjects/pdm_toyadmos/dcase2020/test/src/data/synthetic/TimeSeriesSpec.scala:636:39 
[error] 636 |    summon[(Int,Int,Int) =:= tp10.type] // fail
[error]     |                                       ^
[error]     | Cannot prove that (Int, Int, Int) =:= (tp10 : (Int, Double, String)).
[error] -- Error: /home/user/IdeaProjects/pdm_toyadmos/dcase2020/test/src/data/synthetic/TimeSeriesSpec.scala:637:39 
[error] 637 |    summon[(Int,Int,Int) <:< tp10.type] // fail
[error]     |                                       ^
[error]     | Cannot prove that (Int, Int, Int) <:< (tp10 : (Int, Double, String)).

Expectation

I expected equivalence to work on all summon. I detected this problem when trying to use IsMappedBy to check if all tuple members are numeric. This led to finding that summon[Tuple.Map[t40.type, NumericType] =:= t40.type] also fails.

smarter commented 3 years ago

Your failing examples involve tp10 but you don't provide a definition for it. Nevertheless, I think there is no bug here: foo.type is the singleton type of the value foo, so it will be a subtype of the type of foo but it's not equal to it since the type of foo might contain other members, there is nothing specific to tuples here.

hmf commented 3 years ago

@smarter My apologies. All tp10 should be t40 (copy & paste error). Errors are the same. Ok, thank you for the explanation.