Skip to content

Commit

Permalink
Proper sealing of hierarchy rejected in incremental builds if permitt…
Browse files Browse the repository at this point in the history
…ed class is generic (#3490)

* Fixes #3488
  • Loading branch information
srikanth-sankaran authored Dec 27, 2024
1 parent 744717d commit 7cc64b6
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 3 deletions.
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);
}

}

0 comments on commit 7cc64b6

Please sign in to comment.