On Mon, Mar 17, 2014 at 03:12:23PM -0400, Mark Rada wrote:
> Reviewing tests from last week, I am unable to find any tests that check for
> forward references of local variable declarations that check if the
> initializer for a local variable uses itself.
This is tested in A4, not A3. The reason is that in Java, definite
assignment for local variables is a static analysis. Although you
don't have to do the static analysis for Joos, the tests are
included in A4.
For example, there is the A4 test
Je_8_DefiniteAssignment_InitToItself.
> Well, not quite true, I found one test,
> Je_5_AmbiguousInvoke_LocalInOwnInitializer, but it is supposed to fail for a
> different reason and is not clear on the Joos behaviour.
>
> The JLS allows a variable to be used in its own initializer, but I am
> guessing that is because full Java would also perform the definite
> assignment check, which Joos does not include.
>
> This test case would demonstrate the situation:
>
> public class test {
> public test() {
> int a = a = 42;
> }
> }
>
> My compiler fails to allow this, but doesn't fail any type checking tests,
> so I don't think this case is covered by the Joos delta spec and it is not
> in the assignment 3 spec either.
This kind of thing is forbidden by the "local variable in own
initializer" entry in the Joos specification table.
Your Joos compiler should give a compile-time error for your specific
test class. A4 includes similar tests.
> So, can we assume that this will not happen, or should we be performing the
> same forward reference check on locals that we do for fields?
For locals, it is not a forward reference check. The check is that
a local variable must not be used in its own initializer.