Skip to content

Commit

Permalink
Merge branch 'main' into 10060-double-assignment-test
Browse files Browse the repository at this point in the history
  • Loading branch information
niloc132 authored Jan 8, 2025
2 parents d0bcc81 + 39e67c5 commit 076ea26
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 16 deletions.
2 changes: 1 addition & 1 deletion common.ant.xml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
<property name="javac.debug" value="true"/>
<property name="javac.debuglevel" value="lines,vars,source"/>
<property name="javac.encoding" value="utf-8"/>
<property name="javac.release" value="8"/>
<property name="javac.release" value="11"/>
<property name="javac.nowarn" value="true"/>

<!-- javac and errorprone instructions from https://errorprone.info/docs/installation#ant -->
Expand Down
8 changes: 7 additions & 1 deletion dev/core/src/com/google/gwt/dev/jjs/impl/GwtAstBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,13 @@ public void endVisit(YieldStatement x, BlockScope scope) {
try {
SourceInfo info = makeSourceInfo(x);
JExpression expression = pop(x.expression);
push(new JYieldStatement(info, expression));
if (x.switchExpression == null) {
// This is an implicit 'yield' in a case with an arrow - synthesize a break instead and
// wrap with a block so that the child count in JDT and GWT matches.
push(new JBlock(info, expression.makeStatement(), new JBreakStatement(info, null)));
} else {
push(new JYieldStatement(info, expression));
}
} catch (Throwable e) {
throw translateException(x, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,36 +105,39 @@ public void testEnum() {
assertEquals(0, new EnumTester().getGeneratedClasses().size());
}

/**
* This test requires a lot of care and feeding to keep track of which version of Java the test
* classes were built with, and what the current release version is.
*/
public void testJavacWeirdness() {
List<String> classNames = new JavacWeirdnessTester().getGeneratedClasses();
if (classNames.size() == 4) {
// javac8:
// JavacWeirdnessTester$1
if (classNames.size() == 3) {
// javac 11 with --release=11:
// javac 17 with --release=11:
// javac 21 with --release=11:
// JavacWeirdnessTester$2
// JavacWeirdnessTester$2Foo
// JavacWeirdnessTester$3Foo
assertFalse(classNames.get(0) + " should not contain Foo",
classNames.get(0).contains("Foo"));
assertFalse(classNames.get(1) + " should not contain Foo",
classNames.get(1).contains("Foo"));
assertTrue(classNames.get(1) + " should contain Foo", classNames.get(1).contains("Foo"));
assertTrue(classNames.get(2) + " should contain Foo", classNames.get(2).contains("Foo"));
assertTrue(classNames.get(3) + " should contain Foo", classNames.get(3).contains("Foo"));
} else if (classNames.size() == 5) {
// javac22:
// javac 22 with --release=11:
// JavacWeirdnessTester$1
// JavacWeirdnessTester$2
// JavacWeirdnessTester$1Foo
// JavacWeirdnessTester$2Foo
// JavacWeirdnessTester$3Foo
assertFalse(classNames.get(0) + " should not contain Foo",
classNames.get(0).contains("Foo"));
classNames.get(0).contains("Foo"));
assertFalse(classNames.get(1) + " should not contain Foo",
classNames.get(1).contains("Foo"));
classNames.get(1).contains("Foo"));
assertTrue(classNames.get(2) + " should contain Foo", classNames.get(2).contains("Foo"));
assertTrue(classNames.get(3) + " should contain Foo", classNames.get(2).contains("Foo"));
assertTrue(classNames.get(4) + " should contain Foo", classNames.get(3).contains("Foo"));
} else {
fail("Expected 4 or 5 classes, found " + classNames);
fail("Expected 3 classes, found " + classNames);
}
}

Expand Down
2 changes: 1 addition & 1 deletion doc/build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@
sourcepath="${gwt.root}/user/super/com/google/gwt/emul:${gwt.root}/dev/core/super/com/google/gwt/dev/jjs/intrinsic"
encoding="UTF-8"
access="public"
source="${javac.release}"
source="8"
packagenames="${JAVA_PKGS}"
docletpath="${project.build}/../build_tools/doctool/bin"
doclet="com.google.doctool.custom.JavaEmulSummaryDoclet">
Expand Down
2 changes: 2 additions & 0 deletions user/src/com/google/gwt/junit/JUnitShell.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import com.google.gwt.dev.util.arg.ArgHandlerScriptStyle;
import com.google.gwt.dev.util.arg.ArgHandlerSetProperties;
import com.google.gwt.dev.util.arg.ArgHandlerSourceLevel;
import com.google.gwt.dev.util.arg.ArgHandlerStrict;
import com.google.gwt.dev.util.arg.ArgHandlerWarDir;
import com.google.gwt.dev.util.arg.ArgHandlerWorkDirOptional;
import com.google.gwt.junit.JUnitMessageQueue.ClientStatus;
Expand Down Expand Up @@ -299,6 +300,7 @@ public int handle(String[] args, int tagIndex) {
registerHandler(new ArgHandlerFilterJsInteropExports(options));
registerHandler(new ArgHandlerSetProperties(options));
registerHandler(new ArgHandlerClosureFormattedOutput(options));
registerHandler(new ArgHandlerStrict(options));

/*
* ----- Options specific to JUnitShell -----
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public static class IllegalFieldReferenceException extends RuntimeException {
interface Delegate {
/**
* Returns the types any parsed field references are expected to return.
* Multiple values indicates an overload. E.g., in <a href={...}> either a
* Multiple values indicates an overload. E.g., in <code>&lt;a href={...}&gt;</code> either a
* String or a SafeUri is allowed.
*/
JType[] getTypes();
Expand Down
2 changes: 1 addition & 1 deletion user/src/com/google/gwt/user/client/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -853,7 +853,7 @@ static void onClosed() {
}

static String onClosing() {
if (closeHandlersInitialized) {
if (beforeCloseHandlersInitialized) {
Window.ClosingEvent event = new Window.ClosingEvent();
fireEvent(event);
return event.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,4 +494,50 @@ public void testInlinedStringConstantsInCase() {
};
assertEquals(4, value);
}

// https://github.com/gwtproject/gwt/issues/10044
public void testCaseArrowLabelsVoidExpression() {
// Each switch is extracted to its own method to avoid the early return bug.
assertEquals("success", arrowWithVoidExpr());

// Arrow with non-void expr
assertEquals("success", arrowWithStringExpr());
assertEquals("success", arrowWithIntExpr());

// Arrow with a statement - doesn't fail as part of this bug. This exists to verify
// that JDT won't give us a yield with a statement somehow.
assertEquals("success", arrowWithStatement());
}

private static String arrowWithVoidExpr() {
switch(0) {
case 0 -> assertTrue(true);
};
return "success";
}

private static String arrowWithStringExpr() {
switch(0) {
case 0 -> new Object().toString();
};
return "success";
}

private static String arrowWithIntExpr() {
switch(0) {
case 0 -> new Object().hashCode();
};
return "success";
}

private static String arrowWithStatement() {
switch(0) {
case 0 -> {
if (true) {
new Object().toString();
}
}
};
return "success";
}
}
3 changes: 3 additions & 0 deletions user/test/com/google/gwt/dev/jjs/test/Java17Test.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ public void testSwitchExprInlining() {
public void testInlinedStringConstantsInCase() {
assertFalse(isGwtSourceLevel17());
}
public void testCaseArrowLabelsVoidExpression() {
assertFalse(isGwtSourceLevel17());
}

private boolean isGwtSourceLevel17() {
return JUnitShell.getCompilerOptions().getSourceLevel().compareTo(SourceLevel.JAVA17) >= 0;
Expand Down
2 changes: 1 addition & 1 deletion user/test/com/google/gwt/junit/JUnitShellTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testDefaultModuleUrl() throws Exception {
public void testArgOptimize() throws Exception {
parseGoodArgs("-optimize", "8", "-XdisableInlineLiteralParameters",
"-XdisableRemoveDuplicateFunctions", "-XdisableClusterSimilarFunctions",
"-XdisableOrdinalizeEnums", "-XdisableOptimizeDataflow");
"-XdisableOrdinalizeEnums", "-XdisableOptimizeDataflow", "-strict");
}

private void parseGoodArgs(String... argsToUse) {
Expand Down

0 comments on commit 076ea26

Please sign in to comment.