Re: Re: It is a compile-time error if L does not conform to U
Vladimir Reshetnikov <[email protected]>
| Newsgroups | gmane.comp.lang.scala.user,gmane.comp.lang.scala.debate,gmane.comp.lang.scala |
|---|---|
| Message-ID | <CABdyEv-zDDxFe-1u6acfdiSkrjrEOqTHcprHdfOr-RE2TBpoTg@mail.gmail.com> |
Because there were no responses to this question on scala-user or cs.stackexchange, let me extend it to scala-language and scala-debate as well. (note there is an open +100 bounty for this question at http://cs.stackexchange.com/q/41602/8053) -- Thanks Vladimir On Mon, Apr 20, 2015 at 8:30 AM, Vladimir Reshetnikov < [email protected]> wrote: > Because there are no answers yet, I reposted this question at > http://cs.stackexchange.com/q/41602/8053 > > -- > Thanks > Vladimir > > On Tuesday, April 14, 2015 at 1:03:20 PM UTC-7, Vladimir Reshetnikov wrote: >> >> In SLS, 4.4 Type Parameters, there is a requirement: >> >> "The most general form of a first-order type parameter is @a1 . . .@an ± >> t >: L <: U. Here, L, and U are lower and upper bounds that constrain >> possible type arguments for the parameter. *It is a compile-time error >> if L does not conform to U.*" >> >> I'm interested in a particular case of this rule, when it applies to type >> parameters of a generic class definition. IIRC, in early versions of Scala >> this rule was not enforced. One might think this was benign and in worst >> case could only result in an uninstantiable and uninhabited type (and even >> could be useful in some cases, when L and U depend on other type parameters >> and can be simultaneously satisfied with certain substitutions, although >> statically L does not conform to U). But, as I recall, it was demonstrated >> that without this rule it was possible to compile certain non-typesafe >> program, exploiting transitivity of subtyping, that resulted in a >> ClassCastException at runtime, although no explicit casts were involved. I >> tried to find or reconstruct such an example, but so far without success. >> >> Could you please help me to find such an example, or point me to other >> reasons why this rule must be required for the language to be typesafe? >> >> -- >> Thanks >> Vladimir >> > -- > You received this message because you are subscribed to the Google Groups > "scala-user" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to scala-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "scala-user" group. To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/[email protected] For more options, visit https://groups.google.com/d/optout.