TYPE erstellt bei LambdaExpression nun zwei constraints, falls die Parameter/RetType nicht vom Typ ? extends sind. Dann werden die Constraints einmal mit dem eigentlichen Typ T und einem ? extends/super T -Typ generiert

This commit is contained in:
JanUlrich 2015-03-12 12:27:43 +01:00
parent c53eff4f2c
commit 2c6bce344d
2 changed files with 26 additions and 4 deletions

View File

@ -22,9 +22,11 @@ import de.dhbwstuttgart.syntaxtree.type.RefType;
import de.dhbwstuttgart.syntaxtree.type.SuperWildcardType;
import de.dhbwstuttgart.syntaxtree.type.Type;
import de.dhbwstuttgart.syntaxtree.type.TypePlaceholder;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import de.dhbwstuttgart.typeinference.ConstraintsSet;
import de.dhbwstuttgart.typeinference.FunN;
import de.dhbwstuttgart.typeinference.JavaCodeResult;
import de.dhbwstuttgart.typeinference.OderConstraint;
import de.dhbwstuttgart.typeinference.ResultSet;
import de.dhbwstuttgart.typeinference.SingleConstraint;
import de.dhbwstuttgart.typeinference.Typeable;
@ -158,12 +160,32 @@ public class LambdaExpression extends Expr{
TypePlaceholder tph = TypePlaceholder.fresh(this);
tphParamTypes.add(tph);
// PN < TPH PN
ret.add(new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this)));
if(pT instanceof WildcardType){
ret.add(new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this)));
}else{
OderConstraint orCons = new OderConstraint();
SuperWildcardType superpT = new SuperWildcardType(pT.getOffset(), (ObjectType) pT);
SingleConstraint cons1 = new SingleConstraint(tph.TYPE(assumptions, this), superpT.TYPE(assumptions, this));
SingleConstraint cons2 = new SingleConstraint(tph.TYPE(assumptions, this), pT.TYPE(assumptions, this));
orCons.addConstraint(cons1);
orCons.addConstraint(cons2);
ret.add(orCons);
}
}
Type retType = method_body.getType();
Type tphRetType = TypePlaceholder.fresh(this);
// PN < TPH PN
ret.add(new SingleConstraint(retType.TYPE(assumptions, this), tphRetType.TYPE(assumptions, this)));
if(retType instanceof WildcardType){
ret.add(new SingleConstraint(retType.TYPE(assumptions, this), tphRetType.TYPE(assumptions, this)));
}else{
OderConstraint orCons = new OderConstraint();
SuperWildcardType superretType = new SuperWildcardType(retType.getOffset(), (ObjectType) retType);
SingleConstraint cons1 = new SingleConstraint(tphRetType.TYPE(assumptions, this), superretType.TYPE(assumptions, this));
SingleConstraint cons2 = new SingleConstraint(tphRetType.TYPE(assumptions, this), retType.TYPE(assumptions, this));
orCons.addConstraint(cons1);
orCons.addConstraint(cons2);
ret.add(orCons);
}
ret.add(new SingleConstraint(new FunN(tphRetType, tphParamTypes).TYPE(assumptions, this),this.getType().TYPE(assumptions, this)));
return ret;

View File

@ -1,6 +1,6 @@
class BoundedGenericTest<A extends String>{
class BoundedGenericTest{
var = "test";
<B extends A> B methode(){
methode(){
return var;
}
}