Bug 429192 - More powerful auto-casting after "instanceof" expressions
Summary: More powerful auto-casting after "instanceof" expressions
Status: NEW
Alias: None
Product: Xtend
Classification: Tools
Component: Backlog (show other bugs)
Version: 2.5.3   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Project Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-02-26 16:14 EST by Heribert Schütz CLA
Modified: 2019-08-08 06:21 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Heribert Schütz CLA 2014-02-26 16:14:36 EST
In code like

    if (v instanceof C)
        v.someMethodOfC(...)

the Xtend 2.5 type checker propagates the information that v is an instance of C into the "then" clause of the "if" statement.

It would be nice if this information were propagated in more cases:

*   if (someCondition && v instanceof C && someOtherCondition)
        v.someMethodOfC(...)

*   v instanceof C && v.someBooleanPropertyOfC

*   if (!v instanceof C)
        someExpression
    else
        someCodeExpectingC(v)

*   if (!v instanceof C)
        throw someException // or return;
    someCodeExpectingC(v)

*   if (!(v instanceof C) || v.someBooleanPropertyOfC || !(w instanceof D))
        throw someException
    someCodeExpectingCandD(v, w)

*   if (v instanceof C && v instanceof D) {
        someCodeExpectingC(v)
        someCodeExpectingD(v)
    }

So how far should this go?  I could imagine that the type information may be propagated along the same lines as truth and reachability are propagated by JDT's reachability checker (see also bug #429188), which is stronger than the notion of reachability defined in the Java language spec.
Comment 1 Tamas Miklossy CLA 2019-08-08 06:21:28 EDT
See also https://github.com/eclipse/xtext-xtend/issues/477