Bug 14198

Summary: AST: CastExpression.getType().resolveBinding() is null
Product: [Eclipse Project] JDT Reporter: Martin Aeschlimann <martinae>
Component: CoreAssignee: Olivier Thomann <Olivier_Thomann>
Status: RESOLVED INVALID QA Contact:
Severity: normal    
Priority: P3    
Version: 2.0   
Target Milestone: 2.0 M6   
Hardware: PC   
OS: Windows 2000   
Whiteboard:

Description Martin Aeschlimann CLA 2002-04-19 04:14:02 EDT
20020418
When resolving the type in a castexpression, the result is always null.
(castExpression.getType().resolveBinding())
Comment 1 Olivier Thomann CLA 2002-04-19 12:04:49 EDT
Could you please let me give me a small example? I tried:
package test0303;

public class 
Test {
  void foo() {
    char x;
    x = (char)3;
  }
}

But I could not reproduce it. I will try 
different kind of cast expression.
Comment 2 Olivier Thomann CLA 2002-04-19 12:19:48 EDT
I tried:
(java.lang.Object) "s";
(java.lang.Object[]) null;
(int[]) 
null;
(char)3;

and I could not reproduce. A test case is required for further 
investigation.
Comment 3 Martin Aeschlimann CLA 2002-04-19 13:03:44 EDT
This is my testcase: I just realized that it matters that my code is not 
resolvable. When fixing the code, resolving succeeds.

In this code, String can not be resolved.
	public static void goo(Object o) { 
		Vector s= (String) ooo; 
	}
Comment 4 Olivier Thomann CLA 2002-04-19 13:58:59 EDT
What is the type of the ooo variable or field? Is it a Vector?
I think it makes sense that the 
resolution fails if the casting is incorrect. I will double-check when I got a complete test case.
Comment 5 Martin Aeschlimann CLA 2002-04-19 14:08:37 EDT
I'm working on quick fix.
'ooo' is an undefined variable, and I try to resolve the type in the cast
(String) to see if 'ooo' can be 'Object' or 'int' (depending on the cast).

I was hoping that the unresolvable 'ooo' would not influence the resolving of 
the typebinding of the cast.
However, this is a minor thing, don't spend too much time on it.


Comment 6 Olivier Thomann CLA 2002-04-19 14:23:18 EDT
The unresolved name causes the cast expression to have a problem binding. Then when you request 
the resolution of the type, you end up with null. This is normal. There is no garantee that the 
binding resolution can succeed with incorrect code. And in this case we cannot do better.
Ok to 
close?
Comment 7 Olivier Thomann CLA 2002-04-19 16:32:30 EDT
This is not a bug. When the binding resolution cannot complete, the resolveBinding() method 
returns null.
Closed.