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

8266436: Synthetic constructor trees have non-null return type #3842

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -996,7 +996,7 @@ public JCMethodDecl MethodDef(MethodSymbol m, Type mtype, JCBlock body) {
new JCMethodDecl(
Modifiers(m.flags(), Annotations(m.getRawAttributes())),
m.name,
Type(mtype.getReturnType()),
m.name != names.init ? Type(mtype.getReturnType()) : null,
TypeParams(mtype.getTypeArguments()),
null, // receiver type
Params(mtype.getParameterTypes(), m),
Expand Down
24 changes: 19 additions & 5 deletions test/langtools/tools/javac/parser/JavacParserTest.java
Expand Up @@ -23,7 +23,7 @@

/*
* @test
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050
* @bug 7073631 7159445 7156633 8028235 8065753 8205418 8205913 8228451 8237041 8253584 8246774 8256411 8256149 8259050 8266436
* @summary tests error and diagnostics positions
* @author Jan Lahoda
* @modules jdk.compiler/com.sun.tools.javac.api
Expand Down Expand Up @@ -1758,6 +1758,23 @@ class Test {
codes);
}

@Test //JDK-8266436
void testSyntheticConstructorReturnType() throws IOException {
String code = """
package test;
public class Test {
}
""";

JavacTaskImpl ct = (JavacTaskImpl) tool.getTask(null, fm, null,
null, null, Arrays.asList(new MyFileObject(code)));
CompilationUnitTree cut = ct.parse().iterator().next();
ct.analyze();
ClassTree clazz = (ClassTree) cut.getTypeDecls().get(0);
MethodTree constr = (MethodTree) clazz.getMembers().get(0);
assertEquals("expected null as constructor return type", constr.getReturnType(), null);
}

void run(String[] args) throws Exception {
int passed = 0, failed = 0;
final Pattern p = (args != null && args.length > 0)
Expand Down Expand Up @@ -1816,10 +1833,7 @@ void assertEquals(String message, int i, long l) {
}

void assertEquals(String message, Object o1, Object o2) {
if (o1 != null && o2 != null && !o1.equals(o2)) {
fail(message);
}
if (o1 == null && o2 != null) {
if (!Objects.equals(o1, o2)) {
fail(message);
}
}
Expand Down