-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
3 - WorkingArea-CompilersFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesLanguage-C#
Milestone
Description
[Fact]
public void TypeOf_02()
{
CSharpCompilation c = CreateCompilation(new[] { @"
class List<T> { }
class C<T, TClass, TStruct>
where TClass : class
where TStruct : struct
{
void M()
{
_ = typeof(C<int, object, int>?);
_ = typeof(T?);
_ = typeof(TClass?);
_ = typeof(TStruct?);
_ = typeof(List<T?>);
_ = typeof(List<TClass?>);
_ = typeof(List<TStruct?>);
}
}
", NonNullTypesTrue, NonNullTypesAttributesDefinition });
// PROTOTYPE(NullableReferenceTypes): should nullable reference types be disallowed in `typeof`?
c.VerifyDiagnostics(
// (10,20): error CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.
// _ = typeof(T?);
Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(10, 20),
// (13,25): error CS8627: A nullable type parameter must be known to be a value type or non-nullable reference type. Consider adding a 'class', 'struct', or type constraint.
// _ = typeof(List<T?>);
Diagnostic(ErrorCode.ERR_NullableUnconstrainedTypeParameter, "T?").WithLocation(13, 25)
);
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
3 - WorkingArea-CompilersFeature - Nullable Reference TypesNullable Reference TypesNullable Reference TypesLanguage-C#