rpau / javalang-compiler

Java compiler elements (symbol and type tables) to perform code semantic analysis
GNU Lesser General Public License v3.0
10 stars 4 forks source link

type propagation error with nested classes and anonymous inner class #65

Open cal101 opened 7 years ago

cal101 commented 7 years ago

I need help on solving this. The problem is that the symbol data of the getOuter() is resolved to "Object" and I don't know how this should be solved.

TypeVisitorAdaper, public void visit(MethodCallExpr n, A arg) is reponsible coordinating calculating the symbol data of that. For the current case the "else"-branch of "if (MethodInspector.isGeneric(m)) {" would solve the problem, but I fail to see a sufficient condition to add to the if. I don't find a way to express that the return value is already completely defined.

The other way would be enhancing the "then" branch to come to the same result as methodSymbol.type already has. But I fail to see how (programmatically) and why (conceptually, type resolution rules) the type variable "T" should become bound to StringBuilder. Currently the then branch gets the declared class as scope which also may be be source of the problem. I think I understand the java type resolution rules here but lack some understanding how that transfers to the scopes and scope stacking .

test case: https://github.com/cal101/javalang-compiler/tree/stacked-generic-and-anonymous https://github.com/cal101/javalang-compiler/commit/ea97a34573cd4fd17cedd9253dea6206778af33f

https://github.com/cal101/javalang-compiler/commit/abac510156a1f9eb7a7702222ada2c9991b63baf