Skip to content

[Version 9.0] Feature support for top level statements#1454

Draft
BillWagner wants to merge 2 commits intodraft-v9from
v9-toplevel-statements
Draft

[Version 9.0] Feature support for top level statements#1454
BillWagner wants to merge 2 commits intodraft-v9from
v9-toplevel-statements

Conversation

@BillWagner
Copy link
Member

This PR contains the work for Top-level statements in C# 9.

The commits from #980 were squashed to the first commit on this branch.

The ANTLR grammar is failing. I admit I'm not sure why. There are no grammar changes in this PR.

Add support for top-level statements

Add support for top-level statements

fix md formatting

tweak generated entry-point signature table

Update basic-concepts.md

Add mention of attribute System.Runtime.CompilerServices.CallerMemberName

mention invoking method in top-level statement situation

fix link
@BillWagner BillWagner force-pushed the v9-toplevel-statements branch from d872f61 to 07946a2 Compare November 6, 2025 20:05
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 7, 2025
@RexJaeschke RexJaeschke added the Review: pending Proposal is available for review label Nov 7, 2025
@RexJaeschke
Copy link
Contributor

RexJaeschke commented Nov 7, 2025

@BillWagner There is one grammar change: the extension of compilation_unit to allow statement_list* before namespace_member_declaration*.

@BillWagner BillWagner changed the title Feature support for top level statements [Version 9.0] Feature support for top level statements Nov 7, 2025
@RexJaeschke RexJaeschke added the type: feature This issue describes a new feature label Nov 11, 2025
@Nigel-Ecma Nigel-Ecma self-assigned this Nov 19, 2025
Comment on lines +774 to +775
- The scope of a name defined by an *extern_alias_directive* ([§14.4](namespaces.md#144-extern-alias-directives)) extends over the *using_directive*s, *global_attributes*, *statement_list*s, and *namespace_member_declaration*s of its immediately containing *compilation_unit* or *namespace_body*. An *extern_alias_directive* does not contribute any new members to the underlying declaration space. In other words, an *extern_alias_directive* is not transitive, but, rather, affects only the *compilation_unit* or *namespace_body* in which it occurs.
- The scope of a name defined or imported by a *using_directive* ([§14.5](namespaces.md#145-using-directives)) extends over the *global_attributes*, *statement_list*s, and *namespace_member_declaration*s of the *compilation_unit* or *namespace_body* in which the *using_directive* occurs. A *using_directive* may make zero or more namespace or type names available within a particular *compilation_unit* or *namespace_body*, but does not contribute any new members to the underlying declaration space. In other words, a *using_directive* is not transitive but rather affects only the *compilation_unit* or *namespace_body* in which it occurs.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just made these two edits (after working on the V10 feature "File-Scoped Namespaces," which further changes these two bullet items). Now that top-level statements (statement_lists) are permitted immediately before namespace_member_declarations, we need to make sure those statements are in the scope of these two directives.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants