#!/bin/java bsh.Interpreter

source("TestHarness.bsh");

import bsh.ForBodyNameSpace;

/**
	The standard beanshell auto local variable allocation for untyped vars 
	would cause inconsistency with java in the case of for-init vars.

	This causes particular trouble for new users who aren't trying to do 
	anything fancy and simply want it to act like Java.

	So in 1.1a9 we we simply changed the rules for this case to make it act like
	Java...  If anyone really has trouble with this they can set the flag in 
	ForBodyNameSpace.java and turn it back.
*/
i=1;
for(i=2, a=5; i<10; i++) { 
	assert(a==5);
	assert(i>=2 && i<10);
	patfj=42;
}

//assert(i==1);  old behavior
assert(i==10);
//assert(a==void);  old behavior
assert(a==5);
assert(patfj==42);

// with types the spot where allocation occurs is always clear 
int i=5;
for(int i=0; i<10; i++) { }
assert(i==5);

zz=5;
for(i=0; i<5; i++) {
	int zz;
	if ( true )
		zz=3;
	assert( zz == 3 );
}
assert(zz==5);

// loops shouldn't keep state of vars defined within them
for(i=0; i<3; i++) {
	assert( q == void );	
	int q=99;
	assert( q == 99 );	
}

// but typed init vars should still work
for(int i2=0; i2<3; i2++) {
	assert( q == void );	
	int q=99;
	assert( q == 99 );	
}
assert( i2 == void );

complete();
