Skip to content

Commit a189d1a

Browse files
authored
add more support for nullable references
1 parent 0d998c2 commit a189d1a

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

standard/statements.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,14 @@ local_variable_initializer
325325

326326
The *local_variable_type* of a *local_variable_declaration* either directly specifies the type of the variables introduced by the declaration, or indicates with the identifier `var` that the type should be inferred based on an initializer. The type is followed by a list of *local_variable_declarator*s, each of which introduces a new variable. A *local_variable_declarator* consists of an *identifier* that names the variable, optionally followed by an “`=`” token and a *local_variable_initializer* that gives the initial value of the variable.
327327

328-
In the context of a local variable declaration, the identifier `var` acts as a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)).When the *local_variable_type* is specified as `var` and no type named `var` is in scope, the declaration is an ***implicitly typed local variable declaration***, whose type is inferred from the type of the associated initializer expression. Implicitly typed local variable declarations are subject to the following restrictions:
328+
In the context of a local variable declaration, the identifier `var` acts as a contextual keyword ([§6.4.4](lexical-structure.md#644-keywords)).When the *local_variable_type* is specified as `var` and no type named `var` is in scope, the declaration is an ***implicitly typed local variable declaration***, whose type is inferred from the type of the associated initializer expression.
329+
330+
For reference types and type parameters that aren't constrained to be a value type, `var` infers an annotated type. For example:
331+
332+
- in `var s = "";` var` is inferred as `string?`
333+
- in `var t = new T();` `var` is inferred as `T?`
334+
335+
Implicitly typed local variable declarations are subject to the following restrictions:
329336

330337
- The *local_variable_declaration* cannot include multiple *local_variable_declarator*s.
331338
- The *local_variable_declarator* shall include a *local_variable_initializer*.

0 commit comments

Comments
 (0)