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

Proper sealing of hierarchy rejected in incremental builds if permitted class is generic #3490

Merged
merged 1 commit into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,11 @@ public static TypeBinding resolveType(TypeBinding type, LookupEnvironment enviro
return type;
}

private static TypeBinding resolveType(TypeBinding type, LookupEnvironment environment, boolean convertGenericToRawType, boolean convertRawToGenericType) {
TypeBinding retVal = resolveType(type, environment, convertGenericToRawType);
return convertRawToGenericType ? retVal.actualType() : retVal;
}

/**
* Default empty constructor for subclasses only.
*/
Expand Down Expand Up @@ -2552,7 +2557,7 @@ public ReferenceBinding[] permittedTypes() {
return this.permittedTypes = this.prototype.permittedTypes();
}
for (int i = this.permittedTypes.length; --i >= 0;)
this.permittedTypes[i] = (ReferenceBinding) resolveType(this.permittedTypes[i], this.environment, false); // re-resolution seems harmless
this.permittedTypes[i] = (ReferenceBinding) resolveType(this.permittedTypes[i], this.environment, false, true); // re-resolution seems harmless; while permitted classes/interfaces cannot be parameterized with type arguments, they are not raw either

return this.permittedTypes;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -667,10 +667,10 @@ public void testMemberTypeOfOtherProject() throws JavaModelException {

//https://bugs.eclipse.org/bugs/show_bug.cgi?id=377401
public void test$InTypeName() throws JavaModelException {
IPath projectPath1 = env.addProject("Project1", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$ //$NON-NLS-2$
IPath projectPath1 = env.addProject("Project1", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$
env.addExternalJars(projectPath1, Util.getJavaClassLibs());

IPath projectPath2 = env.addProject("Project2", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$ //$NON-NLS-2$
IPath projectPath2 = env.addProject("Project2", CompilerOptions.getFirstSupportedJavaVersion()); //$NON-NLS-1$
env.addExternalJars(projectPath2, Util.getJavaClassLibs());

// remove old package fragment root so that names don't collide
Expand Down Expand Up @@ -1725,4 +1725,60 @@ static E getE() {
env.removeProject(projectPath);
}

// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3488
// [Sealed types] Proper sealing of hierarchy rejected in incremental builds if permitted class is generic
public void testIssue3488() throws JavaModelException {
IPath projectPath = env.addProject("Project", "19");
env.addExternalJars(projectPath, Util.getJavaClassLibs());

// remove old package fragment root so that names don't collide
env.removePackageFragmentRoot(projectPath, "");

IPath root = env.addPackageFragmentRoot(projectPath, "src");
env.setOutputFolder(projectPath, "bin");

env.addClass(root, "", "Message",
"""
public sealed abstract class Message permits Request {
public final String id;

protected Message(String id) {
this.id = id;
}
}
""");

env.addClass(root, "", "Request",
"""
public final class Request<T> extends Message { // Error here
public final T payload;

public Request(String id, T payload) {
super(id);
this.payload = payload;
}
}
""");

fullBuild(projectPath);
expectingNoProblems();

env.addClass(root, "", "Request",
"""
public final class Request<T> extends Message { // Error here
public final T payload;

public Request(String id, T payload) {
super(id);
this.payload = payload;
}
}
""");

incrementalBuild(projectPath);
expectingNoProblems();

env.removeProject(projectPath);
}

}
Loading