Skip to content
Permalink
Browse files
8266436: Synthetic constructor trees have non-null return type
Reviewed-by: vromero
  • Loading branch information
Jan Lahoda committed May 5, 2021
1 parent c9873c4 commit a8046c9157c4dca601843c953ce67f7372a87a52
Showing with 20 additions and 6 deletions.
  1. +1 −1 src/jdk.compiler/share/classes/com/sun/tools/javac/tree/TreeMaker.java
  2. +19 −5 test/langtools/tools/javac/parser/JavacParserTest.java
@@ -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),
@@ -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
@@ -1758,6 +1758,23 @@ void testUsupportedTextBlock() throws IOException {
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)
@@ -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);
}
}

1 comment on commit a8046c9

@openjdk-notifier

This comment has been minimized.

Copy link

@openjdk-notifier openjdk-notifier bot commented on a8046c9 May 5, 2021

Please sign in to comment.