8344703: Compiler Implementation for Flexible Constructor Bodies

Reviewed-by: vromero, liach, jlahoda
This commit is contained in:
Maurizio Cimadamore 2025-05-08 15:14:35 +00:00
parent 2ea629f3f2
commit c6ffacb575
39 changed files with 129 additions and 133 deletions

View File

@ -226,7 +226,6 @@ public class Preview {
*/
public boolean isPreview(Feature feature) {
return switch (feature) {
case FLEXIBLE_CONSTRUCTORS -> true;
case PRIMITIVE_PATTERNS -> true;
//Note: this is a backdoor which allows to optionally treat all features as 'preview' (for testing).
//When real preview features will be added, this method can be implemented to return 'true'

View File

@ -266,7 +266,7 @@ public enum Source {
WARN_ON_ILLEGAL_UTF8(MIN, JDK21),
UNNAMED_VARIABLES(JDK22, Fragments.FeatureUnnamedVariables, DiagKind.PLURAL),
PRIMITIVE_PATTERNS(JDK23, Fragments.FeaturePrimitivePatterns, DiagKind.PLURAL),
FLEXIBLE_CONSTRUCTORS(JDK22, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL),
FLEXIBLE_CONSTRUCTORS(JDK25, Fragments.FeatureFlexibleConstructors, DiagKind.NORMAL),
MODULE_IMPORTS(JDK25, Fragments.FeatureModuleImports, DiagKind.PLURAL),
JAVA_BASE_TRANSITIVE(JDK25, Fragments.FeatureJavaBaseTransitive, DiagKind.PLURAL),
PRIVATE_MEMBERS_IN_PERMITS_CLAUSE(JDK19),

View File

@ -3,7 +3,6 @@
* @bug 8325805
* @summary Permit non-superclass instance field assignments before this/super in constructors
* @compile/fail/ref=DA_DUConstructors.out -XDrawDiagnostics DA_DUConstructors.java
* @enablePreview
*/
public class DA_DUConstructors {

View File

@ -1,5 +1,3 @@
DA_DUConstructors.java:23:17: compiler.err.var.might.already.be.assigned: x
DA_DUConstructors.java:42:23: compiler.err.var.might.not.have.been.initialized: x
- compiler.note.preview.filename: DA_DUConstructors.java, DEFAULT
- compiler.note.preview.recompile
DA_DUConstructors.java:22:17: compiler.err.var.might.already.be.assigned: x
DA_DUConstructors.java:41:23: compiler.err.var.might.not.have.been.initialized: x
2 errors

View File

@ -3,7 +3,6 @@
* @bug 8328649
* @summary Verify local classes in constructor prologues don't have enclosing instances
* @compile/fail/ref=LocalClassCtorPrologue.out -XDrawDiagnostics LocalClassCtorPrologue.java
* @enablePreview
*/
class LocalClassCtorPrologue {

View File

@ -1,4 +1,2 @@
LocalClassCtorPrologue.java:16:17: compiler.err.cant.ref.before.ctor.called: x
- compiler.note.preview.filename: LocalClassCtorPrologue.java, DEFAULT
- compiler.note.preview.recompile
LocalClassCtorPrologue.java:15:17: compiler.err.cant.ref.before.ctor.called: x
1 error

View File

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8334258
* @summary Disallow early assignment if FLEXIBLE_CONSTRUCTORS preview feature is not enabled
* @compile/fail/ref=EarlyAssignmentNoPreview1.out -XDrawDiagnostics EarlyAssignmentNoPreview1.java
* @compile/fail/ref=EarlyAssignmentNoPreview1.out --release 24 -XDrawDiagnostics EarlyAssignmentNoPreview1.java
*/
public class EarlyAssignmentNoPreview1 {

View File

@ -1,2 +1,2 @@
EarlyAssignmentNoPreview1.java:12:14: compiler.err.preview.feature.disabled: (compiler.misc.feature.flexible.constructors)
EarlyAssignmentNoPreview1.java:12:14: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.flexible.constructors), 24, 25
1 error

View File

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8334258
* @summary Disallow early assignment if FLEXIBLE_CONSTRUCTORS preview feature is not enabled
* @compile/fail/ref=EarlyAssignmentNoPreview2.out -XDrawDiagnostics EarlyAssignmentNoPreview2.java
* @compile/fail/ref=EarlyAssignmentNoPreview2.out --release 24 -XDrawDiagnostics EarlyAssignmentNoPreview2.java
*/
public class EarlyAssignmentNoPreview2 {

View File

@ -1,2 +1,2 @@
EarlyAssignmentNoPreview2.java:12:14: compiler.err.preview.feature.disabled: (compiler.misc.feature.flexible.constructors)
EarlyAssignmentNoPreview2.java:12:14: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.flexible.constructors), 24, 25
1 error

View File

@ -2,7 +2,7 @@
* @test /nodynamiccopyright/
* @bug 8334258
* @summary Disallow early assignment if FLEXIBLE_CONSTRUCTORS preview feature is not enabled
* @compile/fail/ref=EarlyAssignmentNoPreview3.out -XDrawDiagnostics EarlyAssignmentNoPreview3.java
* @compile/fail/ref=EarlyAssignmentNoPreview3.out --release 24 -XDrawDiagnostics EarlyAssignmentNoPreview3.java
*/
public class EarlyAssignmentNoPreview3 {

View File

@ -1,2 +1,2 @@
EarlyAssignmentNoPreview3.java:12:39: compiler.err.preview.feature.disabled: (compiler.misc.feature.flexible.constructors)
EarlyAssignmentNoPreview3.java:12:39: compiler.err.feature.not.supported.in.source: (compiler.misc.feature.flexible.constructors), 24, 25
1 error

View File

@ -3,7 +3,6 @@
* @bug 8325805
* @summary Permit non-superclass instance field assignments before this/super in constructors
* @compile/fail/ref=EarlyAssignments.out -XDrawDiagnostics EarlyAssignments.java
* @enablePreview
*/
public class EarlyAssignments {

View File

@ -1,29 +1,27 @@
EarlyAssignments.java:21:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:22:17: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:23:23: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:31:21: compiler.err.cant.ref.before.ctor.called: super
EarlyAssignments.java:32:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:33:26: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:34:34: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:36:36: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:40:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:44:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:48:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:66:13: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:67:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:68:25: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:69:31: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:98:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:104:22: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:110:35: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:119:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:124:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:129:29: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:134:17: compiler.err.cant.ref.before.ctor.called: super
EarlyAssignments.java:139:23: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:148:13: compiler.err.cant.assign.initialized.before.ctor.called: x
EarlyAssignments.java:157:13: compiler.err.cant.assign.val.to.var: final, x
EarlyAssignments.java:168:13: compiler.err.cant.ref.before.ctor.called: this
- compiler.note.preview.filename: EarlyAssignments.java, DEFAULT
- compiler.note.preview.recompile
EarlyAssignments.java:20:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:21:17: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:22:23: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:30:21: compiler.err.cant.ref.before.ctor.called: super
EarlyAssignments.java:31:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:32:26: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:33:34: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:35:36: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:39:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:43:21: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:47:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:65:13: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:66:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:67:25: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:68:31: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:97:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:103:22: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:109:35: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:118:17: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:123:22: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:128:29: compiler.err.cant.ref.before.ctor.called: x
EarlyAssignments.java:133:17: compiler.err.cant.ref.before.ctor.called: super
EarlyAssignments.java:138:23: compiler.err.cant.ref.before.ctor.called: this
EarlyAssignments.java:147:13: compiler.err.cant.assign.initialized.before.ctor.called: x
EarlyAssignments.java:156:13: compiler.err.cant.assign.val.to.var: final, x
EarlyAssignments.java:167:13: compiler.err.cant.ref.before.ctor.called: this
26 errors

View File

@ -3,7 +3,6 @@
* @bug 8334488
* @summary Verify the error message generated for early access from inner class
* @compile/fail/ref=EarlyInnerAccessErrorMessageTest.out -XDrawDiagnostics EarlyInnerAccessErrorMessageTest.java
* @enablePreview
*/
public class EarlyInnerAccessErrorMessageTest {
int x;

View File

@ -1,4 +1,2 @@
EarlyInnerAccessErrorMessageTest.java:12:34: compiler.err.cant.ref.before.ctor.called: x
- compiler.note.preview.filename: EarlyInnerAccessErrorMessageTest.java, DEFAULT
- compiler.note.preview.recompile
EarlyInnerAccessErrorMessageTest.java:11:34: compiler.err.cant.ref.before.ctor.called: x
1 error

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8345438
* @summary Verify 'return' allowed in a lambda declared in an early construction context
* @enablePreview
*/
public class EarlyLambdaReturn {

View File

@ -3,7 +3,6 @@
* @bug 8325805
* @summary Verify local class in early construction context has no outer instance
* @compile/fail/ref=EarlyLocalClass.out -XDrawDiagnostics EarlyLocalClass.java
* @enablePreview
*/
public class EarlyLocalClass {
EarlyLocalClass() {

View File

@ -1,4 +1,2 @@
EarlyLocalClass.java:12:32: compiler.err.cant.ref.before.ctor.called: this
- compiler.note.preview.filename: EarlyLocalClass.java, DEFAULT
- compiler.note.preview.recompile
EarlyLocalClass.java:11:32: compiler.err.cant.ref.before.ctor.called: this
1 error

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8334248
* @summary Allow early construction local class constructor method references
* @enablePreview
*/
import java.util.function.Supplier;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
public class EarlyLocalTest1 {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
public class EarlyLocalTest2 {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
public class EarlyLocalTest3 {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
public class EarlyLocalTest4 {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8333313
* @summary Verify references to local classes declared in early construction contexts
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8334037
* @summary Test for compiler crash when local class created in early lambda
* @enablePreview
*/
public class LambdaLocalEarlyCrash {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8334252
* @summary Test lambda declared in early construction context
* @enablePreview
*/
public class LambdaOuterCapture {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8334121
* @summary Anonymous class capturing two enclosing instances fails to compile
* @enablePreview
*/
public class MultiLevelOuterInstance {

View File

@ -3,7 +3,6 @@
* @bug 8194743
* @summary Permit additional statements before this/super in constructors
* @compile/fail/ref=SuperInitFails.out -XDrawDiagnostics SuperInitFails.java
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;
public class SuperInitFails extends AtomicReference<Object> implements Iterable<Object> {

View File

@ -1,36 +1,34 @@
SuperInitFails.java:57:9: compiler.err.cant.ref.before.ctor.called: hashCode()
SuperInitFails.java:62:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:67:9: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:72:23: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:77:23: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:94:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:99:33: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:104:14: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:108:20: compiler.err.not.encl.class: java.lang.Object
SuperInitFails.java:112:17: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:119:22: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:125:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:133:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record1
SuperInitFails.java:138:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record2
SuperInitFails.java:155:31: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:159:15: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:168:13: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:172:17: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:176:24: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:180:18: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:186:28: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:195:25: compiler.err.return.before.superclass.initialized
SuperInitFails.java:200:33: compiler.err.ctor.calls.not.allowed.here
SuperInitFails.java:205:29: compiler.err.redundant.superclass.init
SuperInitFails.java:33:13: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:37:14: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:41:14: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:45:13: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:49:33: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:53:32: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:83:18: compiler.err.ctor.calls.not.allowed.here
SuperInitFails.java:89:13: compiler.err.return.before.superclass.initialized
SuperInitFails.java:150:18: compiler.err.call.must.only.appear.in.ctor
- compiler.note.preview.filename: SuperInitFails.java, DEFAULT
- compiler.note.preview.recompile
SuperInitFails.java:56:9: compiler.err.cant.ref.before.ctor.called: hashCode()
SuperInitFails.java:61:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:66:9: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:71:23: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:76:23: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:93:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:98:33: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:103:14: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:107:20: compiler.err.not.encl.class: java.lang.Object
SuperInitFails.java:111:17: compiler.err.cant.ref.before.ctor.called: super
SuperInitFails.java:118:22: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:124:9: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:132:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record1
SuperInitFails.java:137:9: compiler.err.non.canonical.constructor.invoke.another.constructor: SuperInitFails.Record2
SuperInitFails.java:154:31: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:158:15: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:167:13: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:171:17: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:175:24: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:179:18: compiler.err.cant.ref.before.ctor.called: x
SuperInitFails.java:185:28: compiler.err.cant.ref.before.ctor.called: this
SuperInitFails.java:194:25: compiler.err.return.before.superclass.initialized
SuperInitFails.java:199:33: compiler.err.ctor.calls.not.allowed.here
SuperInitFails.java:204:29: compiler.err.redundant.superclass.init
SuperInitFails.java:32:13: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:36:14: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:40:14: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:44:13: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:48:33: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:52:32: compiler.err.call.must.only.appear.in.ctor
SuperInitFails.java:82:18: compiler.err.ctor.calls.not.allowed.here
SuperInitFails.java:88:13: compiler.err.return.before.superclass.initialized
SuperInitFails.java:149:18: compiler.err.call.must.only.appear.in.ctor
33 errors

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2022, 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -24,7 +24,6 @@
* @test
* @bug 8194743
* @summary Test valid placements of super()/this() in constructors
* @enablePreview
*/
import java.util.concurrent.atomic.AtomicReference;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,10 +21,7 @@
* questions.
*/
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// key: compiler.err.cant.assign.initialized.before.ctor.called
// options: --enable-preview -source ${jdk.version}
class CantAssignInitializedBeforeCtorCalled {
int x = 1;

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2024, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2024, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -22,8 +22,8 @@
*/
// key: compiler.misc.feature.flexible.constructors
// key: compiler.warn.preview.feature.use
// options: --enable-preview -source ${jdk.version} -Xlint:preview
// key: compiler.err.feature.not.supported.in.source
// options: --release 24
class FeatureFlexibleConstructors {
FeatureFlexibleConstructors() {

View File

@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -21,14 +21,15 @@
* questions.
*/
//key: compiler.warn.preview.feature.use.plural
//key: compiler.misc.feature.var.syntax.in.implicit.lambda
//key: compiler.warn.preview.feature.use
//key: compiler.misc.feature.flexible.constructors
//options: -Xlint:preview -XDforcePreview -source ${jdk.version} --enable-preview
import java.util.function.Function;
class PreviewFeatureUse {
void test() {
Function<String, String> f = (var s) -> s;
PreviewFeatureUse() {
System.out.println("early init!");
super();
}
}

View File

@ -0,0 +1,34 @@
/*
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
//key: compiler.warn.preview.feature.use.plural
//key: compiler.misc.feature.var.syntax.in.implicit.lambda
//options: -Xlint:preview -XDforcePreview -source ${jdk.version} --enable-preview
import java.util.function.Function;
class PreviewFeatureUsePlural {
void test() {
Function<String, String> f = (var s) -> s;
}
}

View File

@ -22,9 +22,6 @@
*/
// key: compiler.err.return.before.superclass.initialized
// key: compiler.note.preview.filename
// key: compiler.note.preview.recompile
// options: --enable-preview -source ${jdk.version}
class ReturnBeforeSuperclassInit {
ReturnBeforeSuperclassInit(boolean maybe) {