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

[24] ECJ generates wrong code for primitive pattern with instanceof #3535

Closed
Tracked by #2900
jarthana opened this issue Jan 9, 2025 · 4 comments
Closed
Tracked by #2900
Assignees
Milestone

Comments

@jarthana
Copy link
Member

jarthana commented Jan 9, 2025

Given the code,

	static Integer getInteger() {
		return Integer.MIN_VALUE;
	}
	public int foo() {
		Y<Integer> f = new Y<>();
		f.put(X.getInteger()); // This makes all the difference
		return f.get() instanceof float ? 3 : 2;
	}

Compiled and run, this returns 3 with ECJ but returns 2 with Javac. Inspecting the compiled output, I see this from ECJ:
19: instanceof #3 // class java/lang/Object

which I believe is wrong. With Javac, it's Integer.

BTW, Y is defined as below:

class Y<T> {
    T a;
    T get() {
        return a;
    }
    void put(T val) {
        a= val;
    }
}
@mpalat
Copy link
Contributor

mpalat commented Jan 9, 2025

I will take a look

@mpalat
Copy link
Contributor

mpalat commented Jan 22, 2025

Finally got to this. javac differed earlier -Compiling with Java 24 at EA23 version where this is different and a EA27 version onwards where this result is 3 now as per ECJ behaviour. The above patch is only a unit test case.

mpalat added a commit to mpalat/eclipse.jdt.core that referenced this issue Jan 23, 2025
mpalat added a commit that referenced this issue Jan 23, 2025
…3592)

Patterns - issue #3535 Unit Test for ECJ vs JAVAC difference in behaviour in Primitives in Patterns
@mpalat
Copy link
Contributor

mpalat commented Feb 7, 2025

Interim update: with a MAX, there indeed a difference - ecj is not generating exact coversions - looking into the same.

@stephan-herrmann stephan-herrmann added this to the BETA_JAVA24 milestone Feb 8, 2025
mpalat added a commit to mpalat/eclipse.jdt.core that referenced this issue Feb 20, 2025
mpalat added a commit that referenced this issue Feb 20, 2025
#3744)

exact conversion check - case UNBOXING_AND_WIDENING_PRIMITIVE_CONVERSION
@mpalat mpalat closed this as completed Feb 21, 2025
@mpalat
Copy link
Contributor

mpalat commented Feb 21, 2025

Please refer PR 3744 comment for further details of the fix. just fyi.

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