| Summary: | [Xbase] Full Support for Cast Conversion according to Java Lang Spec | ||
|---|---|---|---|
| Product: | [Modeling] TMF | Reporter: | Robert von Massow <rvonmassow> |
| Component: | Xtext | Assignee: | Project Inbox <tmf.xtext-inbox> |
| Status: | NEW --- | QA Contact: | |
| Severity: | normal | ||
| Priority: | P3 | CC: | btickets, dennis.huebner, eclipse, Holger.Schill, jan, joerg83reichert, karsten.thoms, knut.wannheden, mail, moritz.eysholdt, sebastian.zarnekow, sven.efftinge |
| Version: | 2.0.0 | ||
| Target Milestone: | --- | ||
| Hardware: | All | ||
| OS: | All | ||
| Whiteboard: | |||
| Bug Depends on: | 376037 | ||
| Bug Blocks: | 420959, 476798 | ||
(In reply to comment #0) > Build Identifier: N201104060452 > > The following expression is a valid Xtend snippet (according to the validation > and specification): > > testBug0() { > val it0 = newArrayList() as List<List<String>>; > } > > The compiled result: > public void testBug0() { > ArrayList<Object> _newArrayList = CollectionLiterals.<Object>newArrayList(); > final List<String> it0 = ((java.util.List<java.lang.String>) _newArrayList); > } > > has the following error: > Cannot cast from ArrayList<Object> to List<String> > > Reproducible: Always Sorry, wrong Xtend snippet, I actually used the following: testBug0() { val it0 = newArrayList() as List<String>; } We need to fully implement what is defined in the Java Language Specification ยง5.5: http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#5.5 Some of the conversions are already supported by the ConformanceComputer, but we still need to have - the narrowing primitive conversion http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25363 - the narrowing reference conversion http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#25379 - unchecked conversion http://java.sun.com/docs/books/jls/third_edition/html/conversions.html#190772 Preliminary scheduled for 2.0RC1 postponed to SR1 later see also bug 364931 *** Bug 362239 has been marked as a duplicate of this bug. *** *** Bug 377771 has been marked as a duplicate of this bug. *** *** Bug 381152 has been marked as a duplicate of this bug. *** Still valid with new TS We'll have to introduce the notion of 'proofable distinct types' to support full cast validation. *** Bug 364931 has been marked as a duplicate of this bug. *** *** Bug 389872 has been marked as a duplicate of this bug. *** *** Bug 409238 has been marked as a duplicate of this bug. *** Probably the same as comment #0: import java.util.List class B extends A{} class A {} class Testcase { def main() { val List<A> a={} print(a as List<B>) } def print(List<B> bs){} } Invalid cast of CharSequence to String isn't discovered as well:
class StringCastBug {
def test() {
'''Test''' as String
}
}
Another example
interface IBar<C extends IBar<C>> {}
class Bar implements IBar<Bar> {}
class Foo<T extends IBar<T>> {}
class SubFoo<T extends IBar<T>> extends Foo<T> {}
class Baz {
def baz(Foo<Bar> keyRange) {
keyRange as SubFoo<?>
// Error: Cannot cast from Foo<Bar> to SubFoo<?>
}
}
|
Build Identifier: N201104060452 The following expression is a valid Xtend snippet (according to the validation and specification): testBug0() { val it0 = newArrayList() as List<List<String>>; } The compiled result: public void testBug0() { ArrayList<Object> _newArrayList = CollectionLiterals.<Object>newArrayList(); final List<String> it0 = ((java.util.List<java.lang.String>) _newArrayList); } has the following error: Cannot cast from ArrayList<Object> to List<String> Reproducible: Always