From 3cc447e0e82b8e5d9aaae8c80426193a7f8f806c Mon Sep 17 00:00:00 2001 From: Pontus Melke Date: Thu, 27 Sep 2018 21:28:37 +0200 Subject: [PATCH] Fail on duplicate declarations When compiling source code we will get errors here but for byte code we will load the code but in some cases it will be doing the wrong thing. --- .../src/main/java/org/neo4j/codegen/LocalVariables.java | 6 +++++- .../org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java | 4 +--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/community/codegen/src/main/java/org/neo4j/codegen/LocalVariables.java b/community/codegen/src/main/java/org/neo4j/codegen/LocalVariables.java index 99a8359893d31..392ba08b92b12 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/LocalVariables.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/LocalVariables.java @@ -32,8 +32,12 @@ public class LocalVariables private final AtomicInteger counter = new AtomicInteger( 0 ); private final Map localVariables = new HashMap<>(); - public LocalVariable createNew( TypeReference type, String name ) + LocalVariable createNew( TypeReference type, String name ) { + if ( localVariables.containsKey( name ) ) + { + throw new IllegalStateException( String.format( "Local variable %s already in scope", name ) ); + } LocalVariable localVariable = new LocalVariable( type, name, counter.getAndIncrement() ); localVariables.put( name, localVariable ); //if 64 bit types we need to give it one more index diff --git a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java index 6bb72e61757b7..0f0a0a8a193ef 100644 --- a/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java +++ b/community/codegen/src/main/java/org/neo4j/codegen/bytecode/MethodByteCodeEmitter.java @@ -63,13 +63,11 @@ class MethodByteCodeEmitter implements MethodEmitter private final MethodVisitor methodVisitor; private final MethodDeclaration declaration; private final ExpressionVisitor expressionVisitor; - private final TypeReference base; private Deque stateStack = new LinkedList<>(); - MethodByteCodeEmitter( ClassVisitor classVisitor, MethodDeclaration declaration, TypeReference base ) + MethodByteCodeEmitter( ClassVisitor classVisitor, MethodDeclaration declaration, TypeReference ignore ) { this.declaration = declaration; - this.base = base; for ( Parameter parameter : declaration.parameters() ) { TypeReference type = parameter.type();