Hi, see below for the test program.
Am 08.02.2011 um 21:01 schrieb Igor Peshansky: > Kröhnert, Manfred <manfred.kroehn...@kit.edu> wrote on 02/08/2011 02:49:01 > PM: > >> Hello everyone, >> >> I have a problem with the attached test program. >> >> It declares a class 'Base' and two other classes 'B' and 'C' which >> extend 'Base'. >> On each class a method 'asC(): C' is implemented which returns an >> instance of Class 'C'. >> The class 'Base' contains a static cast operator which invokes 'asC()' >> on the given object. >> >> Afterwards instances of 'B' and 'C' are created in two different ways >> and the objects are then cast to type 'C' by invoking the 'as C' >> operator and by calling the 'asC()' method. >> >> I would expect the program to behave the same in all occasions but it >> aborts with a ClassCastException and produces the following output: >> >> b: 15 >> b as C: 42 >> Uncaught exception at place 0: x10.lang.MultipleExceptions: null >> c: 51 >> x10.lang.ClassCastException: null >> c as C: 51 >> >> b2: 15 >> b2 as C: 42 >> c2: 51 >> c2 as C: 51 >> >> b3: 15 >> at x10::lang::Throwable::fillInStackTrace() >> at x10aux::throwClassCastException() >> at x10aux::ref<C> x10aux::real_class_cast<C>(x10aux::ref<x10:: >> lang::Reference>, bool) >> at x10aux::ClassCastNotPrimitive<x10aux::ref<C>, x10aux::ref<Base> >>> ::_(x10aux::ref<Base>, bool) >> at x10aux::ClassCastPrimitive<x10aux::ref<C>, x10aux::ref<Base> >:: >> _(x10aux::ref<Base>, bool) >> at x10aux::ClassCast<x10aux::ref<C>, x10aux::ref<Base> >:: >> _(x10aux::ref<Base>, bool) >> at x10aux::ref<C> x10aux::class_cast<x10aux::ref<C>, x10aux:: >> ref<Base> >(x10aux::ref<Base>) >> at Hello::main(x10aux::ref<x10::array::Array<x10aux::ref<x10:: >> lang::String> > >) >> at x10aux::BootStrapClosure::apply() >> at x10_lang_Runtime__closure__2::apply() >> at x10::lang::Activity::run() >> at x10::lang::Runtime__Worker::loop(x10aux::ref<x10::lang:: >> SimpleLatch>, bool) >> at x10::lang::Runtime__Worker::apply() >> at x10::lang::Runtime__Pool::apply() >> at x10::lang::Runtime::start(x10aux::ref<x10::lang::VoidFun_0_0>, >> x10aux::ref<x10::lang::VoidFun_0_0>) >> at int x10aux::template_main<x10::lang::Runtime, Hello>(int, char**) >> at main >> at start >> >> Is this a bug in the compiler or in the runtime or is it expected > behaviour? >> I am using the C++ backend with X10DT 2.1.1 on OS X 10.6.6 (Intel). > > Manfred, > > This list strips attachments. If the program is small enough, please > include it verbatim. Otherwise, please either open a JIRA (if you believe > that this disagrees with the language specification) or try to reduce this > to a small test case that can be posted verbatim. > > Thanks, > Igor Thanks for the hint Igor. I didn't know about the list removing attachments. Below is the contents of the file. If this sample is too big to post on the list let me know and I'll open a JIRA next time. Best regards, Manfred ------------------------- Test.x10 -------------------------- public class Hello { public static def main(Array[String]) { val b = new B(15); val c = new C(51); Console.OUT.println("b: " + b.value); Console.OUT.println("b as C: " + (b as C).value); Console.OUT.println("c: " + c.value); Console.OUT.println("c as C: " + (c as C).value); val b2 = get(15); val c2 = get(51); Console.OUT.println("\nb2: " + b2.value); Console.OUT.println("b2 as C: " + (b2.asC()).value); Console.OUT.println("c2: " + c2.value); Console.OUT.println("c2 as C: " + (c2.asC()).value); val b3 = get(15); val c3 = get(51); Console.OUT.println("\nb3: " + b.value); Console.OUT.println("b3 as C: " + (b3 as C).value); Console.OUT.println("c3: " + c3.value); Console.OUT.println("c3 as C: " + (c3 as C).value); } public static def get(i: Int) : Base { if (i < 50) return new B(i); else return new C(i); } } protected class Base { public val value: Int; public def this(value: Int) { this.value = value; } public static operator (base: Base) as C = base.asC(); public def asC(): C = new C(24); } protected class B extends Base { public def this(value: Int) { super(value); } public def asC(): C = new C(42); }; protected class C extends Base { public def this(value: Int) { super(value); } public def asC(): C = this; }; ------------------------- Test.x10 -------------------------- ------------------------------------------------------------------------------ The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE: Pinpoint memory and threading errors before they happen. Find and fix more than 250 security defects in the development cycle. Locate bottlenecks in serial and parallel code that limit performance. http://p.sf.net/sfu/intel-dev2devfeb _______________________________________________ X10-users mailing list X10-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/x10-users