#2 Expression.getType() faills to resolve?

open
nobody
None
5
2002-03-19
2002-03-19
No

We think we have found a bug

Consider the following two classes. We create a class (Tester) which in a
method declares and initializes an new variable called 's' (here String, but
it could be of ANY type - including simple types). Then it calls a method
using 's' as argument.

Our translateDefinition method in class OJTester extracts this method call
and again extracts the argument variable. Then we want to get the type of
the argument (type of 's').

Our problem is that the type of 's' is allways 'null' and not of the
declared type (here String)... ?

Are we wrong in our assumption that this is a bug?

Kind Regards
Kasper & Johannes

---------- class OJTester ----------
public class OJTester instantiates Metaclass extends OJClass
{
public void translateDefinition() throws MOPException
{
OJMethod method = getDeclaredMethod("foo", null);
StatementList body = method.getBody();
MethodCall call = (MethodCall) ( (ExpressionStatement)
body.get(1) ).getExpression();
ExpressionList list = call.getArguments();
try
{
Variable var = (Variable) list.get(0);
OJClass type = var.getType(method.getEnvironment());
System.out.println("TYPE: " + type); // type is allways be NULL! ???
}
catch(Exception e) { System.out.println("ERROR!"); }
}
}
---------- end ----------

---------- class Tester ----------
public class Tester instantiates OJTester
{
public void foo()
{
String s = new String("asdf");
bar(s);
}
private void bar(String s) {}
}
---------- end ----------

Discussion