Skip to content

Commit

Permalink
PR feedback.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlekseyTs committed Nov 19, 2018
1 parent 98df03c commit 6160520
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
9 changes: 6 additions & 3 deletions docs/features/nullable-reference-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ In source, nullable reference types are annotated with `?`.
string? OptString; // may be null
Dictionary<string, object?>? OptDictionaryOptValues; // dictionary may be null, values may be null
```
A warning is reported when annotating a reference type or unconstrained generic type with `?` outside a `#nullable` context.
A warning is reported when annotating a reference type with `?` outside a `#nullable` context.

In metadata, nullable reference types are annotated with a `[Nullable]` attribute.
```c#
Expand All @@ -28,7 +28,8 @@ namespace System.Runtime.CompilerServices
}
```

Each type reference is accompanied by a NullableAttribute with an array of bytes, where 0 is Oblivious, 1 is NotAnnotated and 2 is Annotated.
Each type reference is accompanied by a NullableAttribute with an array of bytes, where 0 is Oblivious, 1 is NotAnnotated and 2 is Annotated.
All value types are marked with flag 0 (oblivious).

To optimize trivial cases the attribute can be omitted, or instead can be replaced with an attribute that takes a single byte value rather than an array.

Expand All @@ -41,7 +42,7 @@ Trivial/optimized cases:

NullableAttribute(1) should be placed on a type parameter definition that has a `class!` constraint.
NullableAttribute(2) should be placed on a type parameter definition that has a `class?` constraint.
Other forms of NullableAttribute ar not emitted on type parameter definitions and are not specially recognized on them.
Other forms of NullableAttribute are not emitted on type parameter definitions and are not specially recognized on them.

The `NullableAttribute` type declaration is synthesized by the compiler if it is not included in the compilation, but is needed to produce the output.

Expand All @@ -58,6 +59,8 @@ string[] Oblivious1; // string~[]~
[Nullable(new[] { 1, 1 })] string[] NotNull2; // string![]!
[Nullable(new[] { 0, 2 })] string[] ObliviousMaybeNull; // string?[]~
[Nullable(new[] { 1, 2 })] string[] NotNullMaybeNull; // string?[]!
int Int; // int
Nullable<int> NullableInt1; // Nullable<int>
```
## Declaration warnings
_Describe warnings reported for declarations in initial binding._
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -967,8 +967,8 @@ public bool ApplyNullableTransforms(byte defaultTransformFlag, ImmutableArray<by
break;

case NullableAnnotation.Unknown:
Debug.Assert((NullableAnnotation)transformFlag == NullableAnnotation.Unknown);
if (result.NullableAnnotation != NullableAnnotation.Unknown && (!result.NullableAnnotation.IsAnyNullable() || !oldTypeSymbol.IsNullableType()))
if (result.NullableAnnotation != NullableAnnotation.Unknown &&
!(result.NullableAnnotation.IsAnyNullable() && oldTypeSymbol.IsNullableType())) // Preserve nullable annotation on Nullable<T>.
{
result = CreateNonLazyType(newTypeSymbol, NullableAnnotation.Unknown, result.CustomModifiers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4814,7 +4814,7 @@ public IEnumerable<int> F()
Diagnostic(ErrorCode.ERR_EncUpdateFailedMissingAttribute, "F").WithArguments("C.F()", "System.Runtime.CompilerServices.IteratorStateMachineAttribute").WithLocation(12, 29));
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/29662")]
[Fact]
public void AddedIteratorStateMachineAttribute()
{
var source0 = MarkedSource(@"
Expand Down Expand Up @@ -4999,7 +4999,7 @@ public async Task<int> F()
Diagnostic(ErrorCode.ERR_EncUpdateFailedMissingAttribute, "F").WithArguments("C.F()", "System.Runtime.CompilerServices.AsyncStateMachineAttribute").WithLocation(6, 28));
}

[Fact(Skip = "https://github.com/dotnet/roslyn/issues/29662")]
[Fact]
public void AddedAsyncStateMachineAttribute()
{
var source0 = MarkedSource(@"
Expand Down

0 comments on commit 6160520

Please sign in to comment.