Bug 104202 - Better locations for assignement errors
Summary: Better locations for assignement errors
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: 3.2 M2   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-07-18 05:51 EDT by anonymous.coward.378 CLA
Modified: 2005-09-20 14:09 EDT (History)
2 users (show)

See Also:


Attachments
Proposed fix (1.00 KB, patch)
2005-07-19 13:15 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression tests updated (861 bytes, patch)
2005-08-05 09:13 EDT, Olivier Thomann CLA
no flags Details | Diff
Regression tests updated (33.11 KB, patch)
2005-08-05 09:13 EDT, Olivier Thomann CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description anonymous.coward.378 CLA 2005-07-18 05:51:59 EDT
It's just a detail, but the assignement errors are misplaced i think:

import java.util.Vector;

public class Test {
    private static Object getVector() {
        return new Vector();
    }
    
    private static void test() {
        int i = getVector(); // the error is on "i"
        i = getVector(); // the error is on "getVector()"
    }
}

i believe the error should be on "=" for both lines.
Comment 1 Markus Keller CLA 2005-07-18 06:06:47 EDT
Moving to JDT/Core.
Comment 2 Olivier Thomann CLA 2005-07-19 13:15:23 EDT
Created attachment 24991 [details]
Proposed fix

I think to be consistent that both errors should be reported against
getVector().
Here is a patch to fix the positions.
Existing tests might need to be updated with this patch.
Comment 3 Olivier Thomann CLA 2005-07-19 13:15:58 EDT
We would then report:
----------
1. ERROR in d:\tests_sources\Test.java
 (at line 9)
	int i = getVector(); // the error is on "i"
	        ^^^^^^^^^^^
Type mismatch: cannot convert from Object to int
----------
2. ERROR in d:\tests_sources\Test.java
 (at line 10)
	i = getVector(); // the error is on "getVector()"
	    ^^^^^^^^^^^
Type mismatch: cannot convert from Object to int
----------
2 problems (2 errors)
Comment 4 anonymous.coward.378 CLA 2005-07-20 03:52:59 EDT
(In reply to comment #2)
> I think to be consistent that both errors should be reported against
> getVector().

the call to getVector() is correct, it's the assignment wich is not. I really
think the error should be on the operator.
Comment 5 Philipe Mulet CLA 2005-07-20 04:42:18 EDT
I would agree to what Olivier is suggesting. Being consistent and blaming the
assigned expression.

Note that given the assignment, it feels like the expression is wrong as it
doesn't match type expectation, and as the message tells: the RHS expression
cannot be converted to LHS type.

Olivier - pls perform the change in HEAD stream only.
Comment 6 anonymous.coward.378 CLA 2005-07-20 05:44:37 EDT
(In reply to comment #5)
> I would agree to what Olivier is suggesting. Being consistent and blaming the
> assigned expression.
> 
> Note that given the assignment, it feels like the expression is wrong as it
> doesn't match type expectation, and as the message tells: the RHS expression
> cannot be converted to LHS type.

the right expression as itself has not any expectation to match, it's the
conversion which is problematic.

i think you think to much about the implementation of the type checker. If you
didn't know how it works, you would agree with the problematic assignement point
of view.
Comment 7 Markus Keller CLA 2005-07-20 06:42:57 EDT
Olivier, could you wait with releasing this fix until Martin is back?
It causes failing test cases in LocalCorrectionsQuickFixTest and
TypeMismatchQuickFixTests. 

Furthermore, I'm not sure whether blaming the expression is really the right
solution. If you consider the same error for method invocations, then the range
is currently not on the expression either:

    static void takeInt(int i) {}
    private static void test() {
        takeInt(getVector()); // the error is on "takeInt"
    }
Comment 8 Olivier Thomann CLA 2005-07-20 08:55:19 EDT
Markus,

I'll wait till Martin is back.

The problem is getVector() in the context of an assignment to an int local
variable. Blaming the getVector() from not being compatible with an int is fine.
The only concern we have here is not being consistent as you mentionned in the
first comment.
The method invocation should also be investigated.
Comment 9 Martin Aeschlimann CLA 2005-07-25 10:09:49 EDT
I'm back, let me know when you release the change.

Comment 10 Olivier Thomann CLA 2005-07-25 10:58:41 EDT
Ok, probably tomorrow.
The fix would be released only in HEAD for now.
Comment 11 Olivier Thomann CLA 2005-08-04 14:22:58 EDT
Martin, I am ready to release. Sorry for the delay.
Comment 12 Olivier Thomann CLA 2005-08-05 09:13:18 EDT
Created attachment 25746 [details]
Regression tests updated
Comment 13 Olivier Thomann CLA 2005-08-05 09:13:41 EDT
Created attachment 25747 [details]
Regression tests updated

For compiler tests.
Comment 14 Olivier Thomann CLA 2005-08-05 09:15:46 EDT
Move to 3.2M2 as this requires more work on the UI side (quick fix implementation).
Comment 15 Olivier Thomann CLA 2005-08-16 16:52:57 EDT
(In reply to comment #6)
> the right expression as itself has not any expectation to match, it's the
> conversion which is problematic.
> 
> i think you think to much about the implementation of the type checker. If you
> didn't know how it works, you would agree with the problematic assignement point
> of view.
What is wrong is the type of the initializer expression in the context of an
assignment. It is perfect fine to report the error on the expression. I don't
see why the operator should be blamed.
Comment 16 Martin Aeschlimann CLA 2005-08-17 06:07:54 EDT
fixed in JDT UI to work with old and new problem locations. Will go in the
20050817 I-rebuild.
Comment 17 Martin Aeschlimann CLA 2005-08-17 08:33:53 EDT
sorry, didnt go into 20050817 I-rebuild. Just HEAD.
Comment 18 Olivier Thomann CLA 2005-08-17 10:44:53 EDT
Fixed and released in HEAD.
Updated existing tests.
Comment 19 Olivier Thomann CLA 2005-09-20 14:09:41 EDT
Verified using I20050920-0010 for 3.2M2