From 2206fc5fe5af57911cf3389d844734424d6cb011 Mon Sep 17 00:00:00 2001 From: Manoj N Palat Date: Wed, 27 Mar 2024 08:52:20 +0530 Subject: [PATCH] fixes #2187 (#2225) * fixes #2181 * Fixing the tests --- .../internal/compiler/ast/ConstructorDeclaration.java | 2 ++ .../jdt/internal/compiler/codegen/CodeStream.java | 9 ++++++++- .../core/tests/dom/ASTConverterSuperAfterStatements.java | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java index 8d5b510c773..4bd1828ab05 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/ConstructorDeclaration.java @@ -456,7 +456,9 @@ private void internalGenerateCode(ClassScope classScope, ClassFile classFile) { // generate statements if (this.statements != null) { for (Statement statement : this.statements) { + codeStream.stmtInPreConContext = statement.inPreConstructorContext; statement.generateCode(this.scope, codeStream); + codeStream.stmtInPreConContext = false; if (!this.compilationResult.hasErrors() && codeStream.stackDepth != 0) { this.scope.problemReporter().operandStackSizeInappropriate(this); } diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java index 90399711ee4..20c7b9e0532 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/codegen/CodeStream.java @@ -127,6 +127,7 @@ public class CodeStream { public Map> patternAccessorMap = new HashMap<>(); public Stack accessorExceptionTrapScopes = new Stack<>(); + public boolean stmtInPreConContext = false; public CodeStream(ClassFile givenClassFile) { this.targetLevel = givenClassFile.targetJDK; @@ -224,6 +225,7 @@ private static final void swap(int a[], int i, int j, int result[]) { public void aaload() { this.countLabels = 0; this.stackDepth--; + popTypeBinding(); if (this.classFileOffset >= this.bCodeStream.length) { resizeByteArray(); } @@ -4777,7 +4779,7 @@ public void invoke(byte opcode, MethodBinding methodBinding, TypeBinding declari case Opcodes.OPC_invokespecial : receiverAndArgsSize = 1; // receiver if (methodBinding.isConstructor()) { - if (declaringClass.isNestedType()) { + if (declaringClass.isNestedType() && !this.stmtInPreConContext) { ReferenceBinding nestedType = (ReferenceBinding) declaringClass; // enclosing instances receiverAndArgsSize += nestedType.getEnclosingInstancesSlotSize(); @@ -7776,6 +7778,7 @@ private void pushTypeBinding(int nPop, TypeBinding typeBinding) { pushTypeBinding(typeBinding); } private TypeBinding popTypeBinding() { +// debugStackDepth(this.stackDepth); return isSwitchStackTrackingActive() ? this.switchSaveTypeBindings.pop() : null; } private void popTypeBinding(int nPop) { @@ -7832,4 +7835,8 @@ public void handleRecordAccessorExceptions(BlockScope scope) { invokeJavaLangMatchExceptionConstructor(); // [MatchException] athrow(); } +void debugStackDepth(int stackDepth1) throws IllegalArgumentException{ + if (stackDepth1 < 0) + throw new IllegalArgumentException(); +} } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterSuperAfterStatements.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterSuperAfterStatements.java index db9c2fbc1cf..317ebd29b8c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterSuperAfterStatements.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterSuperAfterStatements.java @@ -198,7 +198,7 @@ public static void main(String[] args) { } - public void _test004() throws JavaModelException { + public void test004() throws JavaModelException { if (!isJRE22) { printJREError(); return;