-
Notifications
You must be signed in to change notification settings - Fork 21
Worse type inference when writing (x: Foo[_ >: A])
as opposed to [A1 >: A](x: Foo[A1])
#10920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Note: it would be cleaner to use a bounded wildcard: def intersect(that: Set[_ >: A]): C Unfortunately that would result in worse type inference, see scala/bug#10920
Note: it would be cleaner to use a bounded wildcard: def intersect(that: Set[_ >: A]): C Unfortunately that would result in worse type inference, see scala/bug#10920
Note: it would be cleaner to use a bounded wildcard: def intersect(that: Set[_ >: A]): C Unfortunately that would result in worse type inference, see scala/bug#10920
Note: it would be cleaner to use a bounded wildcard: def intersect(that: Set[_ >: A]): C Unfortunately that would result in worse type inference, see scala/bug#10920
[A1 >: A](x: Foo[A])
as opposed to (x: Foo[_ >: A])
[A1 >: A](x: Foo[A1])
as opposed to (x: Foo[_ >: A])
Haven't looked closely, but does this conflict with #10819? |
Don't think so, in both cases we should minimize the type variables because they appear in covariant or invariant positions |
The problem that I was thinking of (maybe wrongly) was that we’d need to
derive constraints only from type parameter bounds (and not from values).
Let me take a closer look before commenting more randomly
…On Wed, Nov 14, 2018 at 14:27 Guillaume Martres ***@***.***> wrote:
Don't think so, in both cases we should minimize the type variables
because they appear in covariant or invariant positions
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#10920 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAFjyx8fFb4F5Zd_WLHwzwSwu8vpq8qjks5uvBoqgaJpZM4UZNm3>
.
|
Isn't the occurrence as a lower bound in contravariant position? def bar1(x: Foo[_ >: A]): Foo[A] |
Yes, but it also appears in an invariant position (the |
Ok then at least we know where to look. scalac considers only the formal parameter types to compute the variance of type parameters: I tried adding the result type there but it caused breakage elsewhere. |
There must be more to the story because this works fine: scala> case class Fn[A, B](f: A => B)
// defined case class Fn
scala> Fn((s: String) => s.length)
val res0: Fn[String, Int] = Fn(rs$line$2$$$Lambda$1703/752060661@4207852d) Although |
Can we avoid the existential in the collections in favor of the type param? I think we're out of time to fix the typer for 2.13. |
[A1 >: A](x: Foo[A1])
as opposed to (x: Foo[_ >: A])
(x: Foo[_ >: A])
as opposed to [A1 >: A](x: Foo[A1])
Yes, this affects |
to work around scala/bug#10920
Workaround in scala/scala#7630. Unassigning and rescheduling to 2.14. |
In the following code,
bar1
andbar2
are equivalent:However, type inference works better for
bar2
(in Dotty, both are inferred toFoo[Int]
):It'd be good to figure out whether or not this can be fixed since this affects the API of the collections, in 2.13 we currently have in
Seq
:Which means that in the following code,
x
is inferred to have typeBuffer[Any]
and notBuffer[Int]
:/cc @adriaanm @szeiger
The text was updated successfully, but these errors were encountered: