Bug 14198 - AST: CastExpression.getType().resolveBinding() is null
Summary: AST: CastExpression.getType().resolveBinding() is null
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-04-19 04:14 EDT by Martin Aeschlimann CLA
Modified: 2002-04-19 16:32 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.