Function argument funktioniert nicht #176

Closed
opened 2015-09-23 22:45:24 +00:00 by pl · 5 comments
Owner

bytecode.Matrix_lambdaTest.jav:

class Matrix {
op = (f) -> f.apply(2);
}

ergibt folgende Fehlermeldung:

de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException: Der Typ Fun1< TPH R1834188994, java.lang.Integer > ist nicht in den Assumptions vorhanden
at de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions.getClassAssumptionFor(TypeAssumptions.java:415)
at de.dhbwstuttgart.syntaxtree.statement.Receiver.getReceiverClass(Receiver.java:112)
at de.dhbwstuttgart.syntaxtree.statement.MethodCall.genByteCode(MethodCall.java:332)
at de.dhbwstuttgart.syntaxtree.statement.Return.genByteCode(Return.java:138)
at de.dhbwstuttgart.syntaxtree.statement.Block.genByteCode(Block.java:264)
at de.dhbwstuttgart.bytecode.MethodGenerator.createMethod(MethodGenerator.java:26)
at de.dhbwstuttgart.syntaxtree.statement.LambdaExpression.genByteCode(LambdaExpression.java:260)
at de.dhbwstuttgart.syntaxtree.FieldDeclaration.genByteCode(FieldDeclaration.java:182)
at de.dhbwstuttgart.syntaxtree.Class.genByteCode(Class.java:107)
at de.dhbwstuttgart.syntaxtree.SourceFile.generateBytecode(SourceFile.java:1840)
at de.dhbwstuttgart.core.MyCompiler.generateBytecode(MyCompiler.java:868)
at bytecode.SingleClassTester.compileToBytecode(SingleClassTester.java:22)
at bytecode.Matrix_lambdaTest.test(Matrix_lambdaTest.java:12)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)

bytecode.Matrix_lambdaTest.jav: class Matrix { op = (f) -> f.apply(2); } ergibt folgende Fehlermeldung: de.dhbwstuttgart.typeinference.exceptions.TypeinferenceException: Der Typ Fun1< TPH R1834188994, java.lang.Integer > ist nicht in den Assumptions vorhanden at de.dhbwstuttgart.typeinference.assumptions.TypeAssumptions.getClassAssumptionFor(TypeAssumptions.java:415) at de.dhbwstuttgart.syntaxtree.statement.Receiver.getReceiverClass(Receiver.java:112) at de.dhbwstuttgart.syntaxtree.statement.MethodCall.genByteCode(MethodCall.java:332) at de.dhbwstuttgart.syntaxtree.statement.Return.genByteCode(Return.java:138) at de.dhbwstuttgart.syntaxtree.statement.Block.genByteCode(Block.java:264) at de.dhbwstuttgart.bytecode.MethodGenerator.createMethod(MethodGenerator.java:26) at de.dhbwstuttgart.syntaxtree.statement.LambdaExpression.genByteCode(LambdaExpression.java:260) at de.dhbwstuttgart.syntaxtree.FieldDeclaration.genByteCode(FieldDeclaration.java:182) at de.dhbwstuttgart.syntaxtree.Class.genByteCode(Class.java:107) at de.dhbwstuttgart.syntaxtree.SourceFile.generateBytecode(SourceFile.java:1840) at de.dhbwstuttgart.core.MyCompiler.generateBytecode(MyCompiler.java:868) at bytecode.SingleClassTester.compileToBytecode(SingleClassTester.java:22) at bytecode.Matrix_lambdaTest.test(Matrix_lambdaTest.java:12) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:483) at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99) at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75) at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45) at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71) at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35) at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42) at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34) at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Owner

Gefixt!
Siehe commit 46291a6056

Gefixt! Siehe commit 46291a60565b06386c034dbacdc40009d27446cf
Author
Owner

Folgendes funktioniert nicht. Warum?
class Test3 {
public static void main(String[] args){
Matrix m2 = new Matrix();
m2.op.apply((Integer x) -> x);
}
}

javac -Xdiags:verbose Test.java
Test.java:34: error: method apply in interface Fun1<A,B> cannot be applied to given types;
m2.op.apply((Integer x) -> x);
^
required: Object
found: (Integer x)->x
reason: argument mismatch; Object is not a functional interface
where A,B are type-variables:
A extends Object declared in interface Fun1
B extends Object declared in interface Fun1
1 error

Folgendes funktioniert nicht. Warum? class Test3 { public static void main(String[] args){ Matrix m2 = new Matrix(); m2.op.apply((Integer x) -> x); } } javac -Xdiags:verbose Test.java Test.java:34: error: method apply in interface Fun1<A,B> cannot be applied to given types; m2.op.apply((Integer x) -> x); ^ required: Object found: (Integer x)->x reason: argument mismatch; Object is not a functional interface where A,B are type-variables: A extends Object declared in interface Fun1 B extends Object declared in interface Fun1 1 error
Owner

(In reply to Martin Plümicke from comment #2)

Folgendes funktioniert nicht. Warum?
class Test3 {
public static void main(String[] args){
Matrix m2 = new Matrix();
m2.op.apply((Integer x) -> x);
}
}

Das verwendete Matrix sieht folgendermaße aus:

class Matrix<A,R> {
Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2));
}

Diese Typisierung hat der Typinferenzalgorithmus errechnet, scheint aber nicht zu stimmen.

der Standard Java-Compiler kompiliert das typisierte Matrix nicht mit der Fehlermeldung:

Matrix.java:3: error: incompatible types: bad return type in lambda expression
Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2));
^
R cannot be converted to A
where R,A are type-variables:
R extends Object declared in class Matrix
A extends Object declared in class Matrix
1 error

(In reply to Martin Plümicke from comment #2) > Folgendes funktioniert nicht. Warum? > class Test3 { > public static void main(String[] args){ > Matrix m2 = new Matrix(); > m2.op.apply((Integer x) -> x); > } > } Das verwendete Matrix sieht folgendermaße aus: class Matrix<A,R> { Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2)); } Diese Typisierung hat der Typinferenzalgorithmus errechnet, scheint aber nicht zu stimmen. der Standard Java-Compiler kompiliert das typisierte Matrix nicht mit der Fehlermeldung: Matrix.java:3: error: incompatible types: bad return type in lambda expression Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2)); ^ R cannot be converted to A where R,A are type-variables: R extends Object declared in class Matrix A extends Object declared in class Matrix 1 error
Owner

Fehler ist lokalisiert. Es muss richtig heißen:

class Lambda2<A,R extends A> {
Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2));
}

Die Abhängigkeit R extends A wird nicht in den Bytecode geschrieben.

Fehler ist lokalisiert. Es muss richtig heißen: class Lambda2<A,R extends A> { Fun1<A, ? super Fun1<R, Integer>> op = (f) -> f.apply(new Integer(2)); } Die Abhängigkeit R extends A wird nicht in den Bytecode geschrieben.
Owner

OLD BUG

OLD BUG
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 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#176
No description provided.