Change regarding conditional expression & capture & lub?
Dan Smith
daniel.smith at oracle.com
Tue Dec 10 07:40:37 PST 2013
No problem. Looks like a section that could use a clarifying example or two.
—Dan
On Dec 10, 2013, at 4:31 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:
> Sorry for being slow in making the connections. Perfectly clear now,
>
> Thanks,
> Stephan
>
> On 12/10/2013 05:05 AM, Dan Smith wrote:
>> On Dec 9, 2013, at 6:28 PM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:
>>
>>> On 12/09/2013 09:40 PM, Dan Smith wrote:
>>>> On Dec 8, 2013, at 8:56 AM, Stephan Herrmann <stephan.herrmann at berlin.de> wrote:
>>>>
>>>>> This doesn't seem directly connected to JSR 335 but I wonder
>>>>> if the following change in behavior has s.t. to do with the
>>>>> type checking we are discussing here:
>>>>>
>>>>> class A{/**/}
>>>>> class B extends A {/**/}
>>>>>
>>>>> class G<T> {
>>>>> G<B> gb=null;
>>>>> G<? super A> gsa=null;
>>>>> G<? super B> l = (true)? gsa : gb;
>>>>> }
>>>>>
>>>>> javac7- rejects this, which corresponds to my understanding of the JLS:
>>>>>
>>>>> (1) capture the types of gsa and gb, respectively.
>>>>> (2) compute the lub
>>>>> (3) detect type mismatch
>>>>>
>>>>> javac8, OTOH, accepts the snippet.
>>>>>
>>>>> Has the specification for any of the three steps been changed?
>>>>
>>>> Yes! Conditional expressions can be poly expressions. See Part D, 15.25.
>>>
>>> I've seen that, but couldn't see a connection because ...
>>>
>>>> The relevant change is that poly conditionals do not perform lub at all. Instead, they simply check that each branch is compatible with the target type, and then consider the expression to have the same type as its target type.
>>>
>>> ... it seems javac applies that rule also to standalone expressions.
>>> Or it considers a variable access as a poly expression... or ...
>>>
>>> IOW, is it expected that the example above is affected by the
>>> spec changes?
>>
>> Yes.
>>
>> A conditional expression does not have to wrap a poly expression to _be_ a poly expression.
>>
>> "A reference conditional expression is a poly expression ***if it appears in an assignment context (5.2) or an invocation context (5.3)***. Otherwise, it is a standalone expression.
>>
>> "Where a poly reference conditional expression appears in a context of a particular kind with target type T (5), its second and third operand expressions similarly appear in a context of the same kind with target type T.
>>
>> "The type of a poly reference conditional expression is the same as its target type.
>>
>> "The type of a standalone reference conditional expression is determined as follows: ..."
>>
>> —Dan
>>
>
More information about the lambda-spec-experts
mailing list