Raw Types in Java-TX #336

Closed
opened 2024-05-16 11:05:09 +00:00 by i21023 · 2 comments
Collaborator

Raw Types funktionieren in Java-TX aktuell nicht wirklich, werden aber z.B. in der TYPE und TYPEStmt Klasse im Zusammenhang mit ConstraintSet im Java-TX Compiler sehr ausgiebig verwendet. Die Frage ist nun wahrscheinlich eher, ob man raw types in Java-TX unterstützen kann/möchte, oder man ggf. den Code vom Compiler refactored und generische Typen korrekt verwendet.

Beispiel:

MySetWrapper.java

import java.util.HashSet;
import java.util.Set;

public class MySetWrapper<A> {
    Set<A> set = new HashSet<>();

    public void addAll(MySetWrapper other) {
        set.addAll(other.set);
    }
}

Foo.java

public class Foo{
    void foo(){
        MySetWrapper mySetWrapper = new MySetWrapper();
        MySetWrapper mySetWrapper2 = new MySetWrapper();
        mySetWrapper.addAll(mySetWrapper2);
    }
}

javac Foo.java compiliert, wenn auch mit warnings.

Das gleiche mit dem Java-TX-Compiler ergibt unaufgelöste Constraints.

Foo.jav

public class Foo{
    foo(){
        var mySetWrapper = new MySetWrapper();
        var mySetWrapper2 = new MySetWrapper();
        mySetWrapper.addAll(mySetWrapper2);
    }
}

Aufruf mit:
javac MySetWrapper.java
java -jar JavaTXCompiler.jar Foo.java

führt zu:

Exception in thread "main" de.dhbwstuttgart.exceptions.TypeinferenceException: Unresolved constraints: [[(? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_hj> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super MySetWrapper<gen_r> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_hj> <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super MySetWrapper<gen_r> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java]]
        at de.dhbwstuttgart.typeinference.unify.TypeUnifyTask.compute(TypeUnifyTask.java:275)
        at de.dhbwstuttgart.typeinference.unify.TypeUnifyTask.compute(TypeUnifyTask.java:63)
        at java.base/java.util.concurrent.RecursiveTask.exec(RecursiveTask.java:110)
        at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387)
        at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312)
        at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843)
        at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808)
        at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188)
Raw Types funktionieren in Java-TX aktuell nicht wirklich, werden aber z.B. in der TYPE und TYPEStmt Klasse im Zusammenhang mit ConstraintSet<A> im Java-TX Compiler sehr ausgiebig verwendet. Die Frage ist nun wahrscheinlich eher, ob man raw types in Java-TX unterstützen kann/möchte, oder man ggf. den Code vom Compiler refactored und generische Typen korrekt verwendet. ### Beispiel: MySetWrapper.java ```java import java.util.HashSet; import java.util.Set; public class MySetWrapper<A> { Set<A> set = new HashSet<>(); public void addAll(MySetWrapper other) { set.addAll(other.set); } } ``` Foo.java ```java public class Foo{ void foo(){ MySetWrapper mySetWrapper = new MySetWrapper(); MySetWrapper mySetWrapper2 = new MySetWrapper(); mySetWrapper.addAll(mySetWrapper2); } } ``` `javac Foo.java` compiliert, wenn auch mit warnings. Das gleiche mit dem Java-TX-Compiler ergibt unaufgelöste Constraints. Foo.jav ```java public class Foo{ foo(){ var mySetWrapper = new MySetWrapper(); var mySetWrapper2 = new MySetWrapper(); mySetWrapper.addAll(mySetWrapper2); } } ``` Aufruf mit: `javac MySetWrapper.java` `java -jar JavaTXCompiler.jar Foo.java` führt zu: ``` Exception in thread "main" de.dhbwstuttgart.exceptions.TypeinferenceException: Unresolved constraints: [[(? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_hj> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super MySetWrapper<gen_r> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hr> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_hj> <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<gen_k> <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_a> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_hs> <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? extends MySetWrapper<YL> =. java.lang.Object, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? extends MySetWrapper<YL> =. ? super MySetWrapper<gen_v>, )@3 in Foo.java, (? super MySetWrapper<gen_r> <. MySetWrapper, )@5 in Foo.java], [(MySetWrapper<YL> =. ? super java.lang.Object, )@3 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(java.lang.Object <. MySetWrapper, )@5 in Foo.java], [(? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? super MySetWrapper<gen_b> <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java, (? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (java.lang.Object <. MySetWrapper, )@5 in Foo.java, (MySetWrapper<gen_f> <. MySetWrapper, )@5 in Foo.java], [(? super java.lang.Object <. MySetWrapper, )@5 in Foo.java, (? extends MySetWrapper<YL> =. MySetWrapper<gen_h>, )@3 in Foo.java]] at de.dhbwstuttgart.typeinference.unify.TypeUnifyTask.compute(TypeUnifyTask.java:275) at de.dhbwstuttgart.typeinference.unify.TypeUnifyTask.compute(TypeUnifyTask.java:63) at java.base/java.util.concurrent.RecursiveTask.exec(RecursiveTask.java:110) at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:387) at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1312) at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1843) at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1808) at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:188) ```
Owner

Man könnte vielleicht Object inferieren. Ich bin allerdings der Meinung, dass man bei einer neuen Sprache nicht unbedingt die Fehler von Java übernehmen sollte. Wie siehst du das, @pl ?

Man könnte vielleicht `Object` inferieren. Ich bin allerdings der Meinung, dass man bei einer neuen Sprache nicht unbedingt die Fehler von Java übernehmen sollte. Wie siehst du das, @pl ?
Owner

In Java-TX sollen keine Raw-Types implementiert werden.

In Java-TX sollen keine Raw-Types implementiert werden.
Sign in to join this conversation.
No Milestone
No project
No Assignees
3 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: JavaTX/JavaCompilerCore#336
No description provided.