changeset 57828:6c3d3494c4c5 patterns-deconstruction

Automatic merge with records-and-sealed
author mcimadamore
date Tue, 10 Sep 2019 23:06:21 +0000
parents 51781035a19a 362ffdb9571b
children 40be0504668d
files src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java
diffstat 3 files changed, 11 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 10 13:54:49 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Flow.java	Tue Sep 10 23:06:21 2019 +0000
@@ -570,6 +570,7 @@
             try {
                 alive = Liveness.ALIVE;
                 scanStat(tree.body);
+                tree.completesNormally = alive != Liveness.DEAD;
 
                 if (alive == Liveness.ALIVE && !tree.sym.type.getReturnType().hasTag(VOID))
                     log.error(TreeInfo.diagEndPos(tree.body), Errors.MissingRetStmt);
@@ -2182,8 +2183,8 @@
                                     checkInit(TreeInfo.diagnosticPositionFor(var, vardecl),
                                         var, Errors.VarNotInitializedInDefaultConstructor(var), isCompactConstructor);
                                 } else {
-                                    boolean wasInitialized = checkInit(TreeInfo.diagEndPos(tree.body), var, isCompactConstructor);
-                                    if (!wasInitialized && var.owner.kind == TYP && isCompactConstructor && uninits.isMember(var.adr)) {
+                                    boolean wasInitialized = checkInit(TreeInfo.diagEndPos(tree.body), var, isCompactConstructor && tree.completesNormally);
+                                    if (!wasInitialized && var.owner.kind == TYP && isCompactConstructor && uninits.isMember(var.adr) && tree.completesNormally) {
                                         /*  this way we indicate Lower that it should generate an initialization for this field
                                          *  in the compact constructor
                                          */
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Sep 10 13:54:49 2019 +0000
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/tree/JCTree.java	Tue Sep 10 23:06:21 2019 +0000
@@ -866,6 +866,9 @@
         public JCExpression defaultValue;
         /** method symbol */
         public MethodSymbol sym;
+        /** does this method completes normally */
+        public boolean completesNormally;
+
         protected JCMethodDecl(JCModifiers mods,
                             Name name,
                             JCExpression restype,
--- a/test/langtools/tools/javac/records/RecordCompilationTests.java	Tue Sep 10 13:54:49 2019 +0000
+++ b/test/langtools/tools/javac/records/RecordCompilationTests.java	Tue Sep 10 23:06:21 2019 +0000
@@ -414,6 +414,11 @@
         // dead code
         assertOK("record R(int x) { { this.x = 0; } public R { if (false) { this.x = x; }} }");
 
+        // throwing an unchecked exception
+        assertOK("record R(int x) { public R { if (x < 0) { this.x = x; throw new RuntimeException(); }} }");
+
+        assertOK("record R(int x) { public R { if (x < 0) { this.x = x; throw new RuntimeException(); }} }");
+
         // x is not DA nor DU in the body of the constructor hence error
         assertFail("compiler.err.var.might.not.have.been.initialized", "record R(int x) { # }",
                 "public R { if (x < 0) { this.x = -x; } }");