You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As described in #16596, if Count1[N,T] fails for N > 2, I would expect any function that uses this match type, to fail also. Strangely enough, it doesn't.
In the example above, replicateT2Ok[T](n:Int) I do not set [T] explicitly in the recursive call. I would expect this to be set to to T. However, it seems like it s set to Nothing, hence making Count1[N,T] and Count0[N,T] have the same final case. I don't know why, but compilation succeeds.
In the example above, replicateT2Fail[T](n:Int) I set [T] explicitly in the recursive call. As expected, I get a compilation error. This error seems to be the one I get in #16596, as is expected. What I do not expect, is to have to set T explicitly in the recursive call. I assumed the compiler would do it automatically.
The text was updated successfully, but these errors were encountered:
The problem with summon[rep1Tc.type <:< Int *: Int *: Int *: EmptyTuple] in scastie is because your snippet uses scala 3.2.1-RC2 and this problem got already fixed in 3.2.1.
The fact that replicateT2Ok is called recursively indeed does not influence how the type parameter is inferred and this is as designed. What is taken into account when inferring type parameters of a method call are the types of term (value) parameters and the expected return type. Having none of these clues the compiler infers Nothing.
Taking the above into account, this issue seems to reduce to a duplicate of #16596
Compiler version
Versions 3.2.1, 3.2.1-RC2 and 3.2.0
Minimized code
Code is available in scastie. This may be related to #16596.
Note: when compiling with 3.2.1 the commented
summons
above compile, but in Scastie, it fails to compile.Output
Expectation
As described in #16596, if
Count1[N,T]
fails forN > 2
, I would expect any function that uses this match type, to fail also. Strangely enough, it doesn't.In the example above,
replicateT2Ok[T](n:Int)
I do not set[T]
explicitly in the recursive call. I would expect this to be set to toT
. However, it seems like it s set toNothing
, hence makingCount1[N,T]
andCount0[N,T]
have the same final case. I don't know why, but compilation succeeds.In the example above,
replicateT2Fail[T](n:Int)
I set[T]
explicitly in the recursive call. As expected, I get a compilation error. This error seems to be the one I get in #16596, as is expected. What I do not expect, is to have to setT
explicitly in the recursive call. I assumed the compiler would do it automatically.The text was updated successfully, but these errors were encountered: