Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing error message for generics on var #600

Closed
joeseibel opened this issue Dec 9, 2022 · 2 comments
Closed

Missing error message for generics on var #600

joeseibel opened this issue Dec 9, 2022 · 2 comments

Comments

@joeseibel
Copy link

An error should be reported when there are generics on var, but the JDT compiler does not complain and compiles anyway. The following class currently compiles and runs, but an error should be reported:

package test;

import java.util.ArrayList;

public class Test {
    public static void main(String[] args) {
        var<String> list = new ArrayList<String>();
        System.out.println(list.size());
    }
}

When I run this class through javac, the following error is produced:

Test.java:7: error: illegal reference to restricted type 'var'
		var<String> list = new ArrayList<String>();
		^
@iloveeclipse
Copy link
Member

iloveeclipse commented Dec 9, 2022

Cool. Looks like ecj ignores the generic part on var completely, which leads to such code to be accepted too:
var<Number> list = new ArrayList<String>();

simfis pushed a commit to simfis/eclipse.jdt.core that referenced this issue Jan 30, 2023
simfis pushed a commit to simfis/eclipse.jdt.core that referenced this issue Jan 30, 2023
simfis pushed a commit to simfis/eclipse.jdt.core that referenced this issue Jan 30, 2023
simfis pushed a commit to simfis/eclipse.jdt.core that referenced this issue Jan 31, 2023
simfis pushed a commit to simfis/eclipse.jdt.core that referenced this issue Feb 16, 2023
@srikanth-sankaran
Copy link
Contributor

srikanth-sankaran pushed a commit to simfis/eclipse.jdt.core that referenced this issue Jun 19, 2023
jarthana pushed a commit to jarthana/eclipse.jdt.core that referenced this issue Jun 27, 2023
…clipse-jdt#600 (eclipse-jdt#672)

* Create compile error in case 'var' reserved type name is used with type arguments. Fixes eclipse-jdt#600

* Create additional test to cover variable declaration in a basic 'for' statement

* Fix changes made to LocalDeclaration.java by removing return statement to restore normal flow of control after adding the problem.
Add new tests for enhanced for statement and try-with-resources statement.

* Adjust @SInCE version for new IProblem constant

---------

Co-authored-by: Simon Fischer <simon@controlsurface.anonaddy.com>
Co-authored-by: Srikanth Sankaran <srikanth.sankaran@advantest.com>
mpalat pushed a commit to mpalat/eclipse.jdt.core that referenced this issue Jul 6, 2023
…clipse-jdt#600 (eclipse-jdt#672)

* Create compile error in case 'var' reserved type name is used with type arguments. Fixes eclipse-jdt#600

* Create additional test to cover variable declaration in a basic 'for' statement

* Fix changes made to LocalDeclaration.java by removing return statement to restore normal flow of control after adding the problem.
Add new tests for enhanced for statement and try-with-resources statement.

* Adjust @SInCE version for new IProblem constant

---------

Co-authored-by: Simon Fischer <simon@controlsurface.anonaddy.com>
Co-authored-by: Srikanth Sankaran <srikanth.sankaran@advantest.com>
subyssurendran666 pushed a commit to subyssurendran666/eclipse.jdt.core that referenced this issue Jul 18, 2023
…clipse-jdt#600 (eclipse-jdt#672)

* Create compile error in case 'var' reserved type name is used with type arguments. Fixes eclipse-jdt#600

* Create additional test to cover variable declaration in a basic 'for' statement

* Fix changes made to LocalDeclaration.java by removing return statement to restore normal flow of control after adding the problem.
Add new tests for enhanced for statement and try-with-resources statement.

* Adjust @SInCE version for new IProblem constant

---------

Co-authored-by: Simon Fischer <simon@controlsurface.anonaddy.com>
Co-authored-by: Srikanth Sankaran <srikanth.sankaran@advantest.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants