Open KuceraMartin opened 3 months ago
Minimisation:
def foo(v: Int): Any = v
def bar[B](f: B => Any): B = ???
val infersInt = bar(x => foo(x))
val infersNothing = bar(foo)
In the first case, we have an explicit parameter which unifies the two constraints B <: x
and x <: Int
.
Whereas in the second case, the parameter from the expansion (say v
) gets a separate type variable (say C
). We then have the constraints B <: C
, C <: v
and v <: Int
, but B
is instantiated later and hence from below.
Compiler version
3.5.0-RC1-bin-20240405-85672a0-NIGHTLY
Minimized code
Output
The types of
a
,b
,c
, andd
are inferred asMyInt
,Int
,Nothing
, andInt
, respectively.Expectation
In the best possible world, I would like all four vals to be of type
Int
becausebox
is of typeInt => MyInt
. SinceMyInt <: Int
, I can understand whyMyInt
might be inferred, but I would at least expect the types ofa
andb
to be the same, and also the types ofc
andd
to be the same.