Description
I'm having difficulty pinning down whether this is still latest spec behavior, and what the rationale for it was. Given that neither the analyzer nor CFE pass this test, it seems like maybe it should be removed?
edit: the analyzer is incorrect here, and this test is valid. Keeping issue open for us to make a fix.
class A {
var x, y;
// This should cause an error because `x` is final when accessed as an
// initializing formal.
A(this.x)
: y = (() {
/*@compile-error=unspecified*/ x = 3;
});
}
From the spec:
Initializing formals constitute an exception to the rule that every formal parameter introduces a local variable into the formal parameter scope (\ref{formalParameters}).
When the formal parameter list of a non-redirecting generative constructor contains any initializing formals, a new scope is introduced, the {\em formal parameter initializer scope}, which is the current scope of the initializer list of the constructor, and which is enclosed in the scope where the constructor is declared.
Each initializing formal in the formal parameter list introduces a final local variable into the formal parameter initializer scope, but not into the formal parameter scope; every other formal parameter introduces a local variable into both the formal parameter scope and the formal parameter initializer scope.
There are no other references to "formal parameter initializer scope," and the section on initializer lists doesn't reference scopes at all, but rather magically talks about:
For each such declaration
$d$ , if$d$ has the form \code{$finalConstVarOrType$$v$ =$e$ ; }
then$e$ is evaluated to an object$o$
and the instance variable$v$ of$i$ is bound to$o$ .
where some scope of evaluation is assumed but not expressed. Similarly, the "formalParameters" section doesn't mention anything either.
I get the feeling, best I can make of this, that the test is correct. However, I'm not confident there, and I'm suspicious of the value that this complexity in the spec adds.