Skip to content

Analyzer fails initializing_formal_final_test #34369

Closed
@MichaelRFairhurst

Description

@MichaelRFairhurst

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P4dart-model-analyzer-specIssues with the analyzer's implementation of the language speclegacy-area-analyzerUse area-devexp instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions