Index: src/Common/PassVisitor.h
===================================================================
--- src/Common/PassVisitor.h	(revision 0f798534e5e22d73c97f4df465f395acdb91f398)
+++ src/Common/PassVisitor.h	(revision 61d9b4b1665e2ecc616141fbd84baeba38a14dcb)
@@ -260,4 +260,6 @@
 
 private:
+	bool inFunction = false;
+
 	template<typename pass_t> friend void acceptAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
 	template<typename pass_t> friend void mutateAll( std::list< Declaration* > &decls, PassVisitor< pass_t >& visitor );
Index: src/Common/PassVisitor.impl.h
===================================================================
--- src/Common/PassVisitor.impl.h	(revision 0f798534e5e22d73c97f4df465f395acdb91f398)
+++ src/Common/PassVisitor.impl.h	(revision 61d9b4b1665e2ecc616141fbd84baeba38a14dcb)
@@ -404,4 +404,8 @@
 			indexerAddId( &func );
 			maybeAccept_impl( node->type, *this );
+			// function body needs to have the same scope as parameters - CompoundStmt will not enter
+			// a new scope if inFunction is true
+			ValueGuard< bool > oldInFunction( inFunction );
+			inFunction = true;
 			maybeAccept_impl( node->statements, *this );
 			maybeAccept_impl( node->attributes, *this );
@@ -434,4 +438,8 @@
 			indexerAddId( &func );
 			maybeMutate_impl( node->type, *this );
+			// function body needs to have the same scope as parameters - CompoundStmt will not enter
+			// a new scope if inFunction is true
+			ValueGuard< bool > oldInFunction( inFunction );
+			inFunction = true;
 			maybeMutate_impl( node->statements, *this );
 			maybeMutate_impl( node->attributes, *this );
@@ -712,6 +720,9 @@
 	VISIT_START( node );
 	{
-		auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
+		// do not enter a new scope if inFunction is true - needs to check old state before the assignment
+		ValueGuard< bool > oldInFunction( inFunction );
+		auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
 		auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
+		inFunction = false;
 		visitStatementList( node->kids );
 	}
@@ -723,6 +734,9 @@
 	MUTATE_START( node );
 	{
-		auto guard1 = makeFuncGuard( [this]() { indexerScopeEnter(); }, [this]() { indexerScopeLeave(); } );
+		// do not enter a new scope if inFunction is true - needs to check old state before the assignment
+		ValueGuard< bool > oldInFunction( inFunction );
+		auto guard1 = makeFuncGuard( [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeEnter(); }, [this, &oldInFunction]() { if ( ! oldInFunction.old ) indexerScopeLeave(); } );
 		auto guard2 = makeFuncGuard( [this]() { call_beginScope();   }, [this]() { call_endScope();     } );
+		inFunction = false;
 		mutateStatementList( node->kids );
 	}
