amelentev / java-oo

Java Operator Overloading
http://amelentev.github.io/java-oo/
268 stars 31 forks source link

javac: binary operator adds erroneous cast on 1st operand. #10

Closed amelentev closed 10 years ago

amelentev commented 10 years ago

For example when multiplying Vector to Matrix:

class VecMat {
    static class Vec {
        Vec multiply(Mat A) { return this; }
    }
    static class Mat {}
    public static void main(String[] s) {
        Vec a = new Vec();
        Mat A = new Mat();
        System.out.println(a*A);
    }
}

a*A transforms to ((Mat)a).multiply(A) which causes ClassCastException at runtime.

amelentev commented 10 years ago

The cast added on TransTypes stage because javac plugin adds a custom method-operator which confused the compiler. Fixed by moving desugar to TransTypes stage.