Skip to content

Support scoped modifier for other local declarations #62039

@cston

Description

@cston

This issue was discussed in LDM 7/27/2022. It is blocked on #62983 (spec existing grammar and consider impact on implementation).

// foreach:
foreach (scoped R r in c1) { }
foreach (scoped ref int i in c2) { }

// for:
for (scoped R r = s; ; ) { }
for (scoped ref int a = ref b; ; ) { }

// deconstruction:
(scoped R x, scoped R y) = F();
scoped var (x, y) = F(); // probably should disallow

// out var:
F(out scoped R r);
F(out scoped var r);

Relates to test plan #59194

To support this, we'd need to expand the grammar to allow modifiers in declaration_expression, for_each_statement, for_statement (see proposal below).

This raises the questions:

  1. do we want to do this?
  2. confirm that scoped would be the only modifier allowed in those positions. Other declaration modifiers (const, static, readonly, volatile) are already not applicable to local declarations.
declaration_expression
  : modifier* type variable_designation // add modifiers
  ;

for_each_statement
  : attribute_list* 'await'? 'foreach' '(' modifier* type identifier_token 'in' expression ')' statement // add modifiers
  ;

for_each_variable_statement
  : attribute_list* 'await'? 'foreach' '(' expression 'in' expression ')' statement // covered by declaration_expression
  ;


fixed_statement
  : attribute_list* 'fixed' '(' variable_declaration ')' statement // probably leave untouched
  ;

for_statement
  : attribute_list* 'for' '(' (modifier* variable_declaration? | (expression (',' expression)*)?) ';' expression? ';' (expression (',' expression)*)? ')' statement // add modifiers
  ;
  
// Local declarations and parameters already support modifiers:

local_declaration_statement
  : attribute_list* 'await'? 'using'? modifier* variable_declaration ';'
  ;

Metadata

Metadata

Assignees

Type

No type

Projects

Status

Active/Investigating

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions