constructor type fix

This commit is contained in:
JanUlrich 2021-11-09 14:48:06 +01:00
parent cc029a5376
commit d777b45166
3 changed files with 9 additions and 2 deletions

View File

@ -24,7 +24,7 @@ object Parser {
def methodCall[_: P]: P[MethodCall] =P( ident ~ paramList ).map(ite => MethodCall(null, ite._1, ite._2) )
def paramList[_: P] : P[List[Expr]]= P("(".! ~ (expr ~ (",".! ~ expr).rep.map(_.toList.map{_._2})).? ~ ")".! ).map(ite => ite._2.map(params => params._1 :: params._2).getOrElse(List.empty))
def variable[_: P]: P[Expr] = P(ident).map(LocalVar)
def expr[_: P]: P[Expr] = constructor | P( variable ~ (prefixMethodCall | fieldVar).rep.map(_.toList) )
def expr[_: P]: P[Expr] = P( (variable | constructor)~ (prefixMethodCall | fieldVar).rep.map(_.toList) )
.map(ite => ite._2.foldLeft(ite._1) { (e1 : Expr, e2 : Expr) =>
e2 match{
case MethodCall(_, name, e3) => MethodCall(e1, name, e3)

View File

@ -78,7 +78,8 @@ object TYPE {
val genericReplace = new GenericTypeReplaceMonad(this)
val es = params.map(ex => TYPEExpr(ex, localVars, ast))
val cl = findClasses(className, ast)
val retCons = es.flatMap(_._2.map(genericReplace.replaceGenerics(_))) ++
val paramCons = cl.fields.map(_._1).zip(es.map(_._1)).map(pair => genericReplace.replaceGenerics(LessDot(pair._2, pair._1)))
val retCons = paramCons ++ es.flatMap(_._2.map(genericReplace.replaceGenerics(_))) ++
cl.genericParams.map(gp => LessDot(genericReplace.replaceGenerics(gp._1), genericReplace.replaceGenerics(gp._2)))
(RefType(className, cl.genericParams.map(_._1).map(genericReplace.replaceGenerics(_))), retCons)
}

View File

@ -52,4 +52,10 @@ class IntegrationTest extends FunSuite {
val result = FJTypeinference.typeinference(input )
println(result.map(Main.prettyPrint(_)))
}
test("fieldVar access"){
val input ="class List<A extends Object> extends Object{\nA f;\nget(){ return this.f; }\n}\n\nclass Test2 extends Object{\nget(){ return new List(this).get();}\n}"
val result = FJTypeinference.typeinference(input )
println(result.map(Main.prettyPrint(_)))
}
}