Skip to content

Initial roll out of !! #64720

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
3 changes: 3 additions & 0 deletions eng/CodeAnalysis.src.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1539,6 +1539,9 @@ dotnet_diagnostic.IDE0160.severity = silent
# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = silent

# IDE0190: Null check can be simplified
dotnet_diagnostic.IDE0190.severity = suggestion

# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = suggestion

Expand Down
3 changes: 3 additions & 0 deletions eng/CodeAnalysis.test.globalconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,9 @@ dotnet_diagnostic.IDE0160.severity = silent
# IDE0161: Convert to file-scoped namespace
dotnet_diagnostic.IDE0161.severity = silent

# IDE0190: Null check can be simplified
dotnet_diagnostic.IDE0190.severity = silent

# IDE1005: Delegate invocation can be simplified.
dotnet_diagnostic.IDE1005.severity = silent

Expand Down
3 changes: 3 additions & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<UsingToolIbcOptimization>false</UsingToolIbcOptimization>
<UsingToolXliff>false</UsingToolXliff>
<LastReleasedStableAssemblyVersion>$(AssemblyVersion)</LastReleasedStableAssemblyVersion>
<UsingToolMicrosoftNetCompilers>true</UsingToolMicrosoftNetCompilers>
</PropertyGroup>
<!--
Servicing build settings for Setup/Installer packages. Instructions:
Expand Down Expand Up @@ -51,6 +52,8 @@
<MicrosoftCodeAnalysisCSharpCodeStyleVersion>4.0.1</MicrosoftCodeAnalysisCSharpCodeStyleVersion>
<MicrosoftCodeAnalysisCSharpVersion>4.0.1</MicrosoftCodeAnalysisCSharpVersion>
<MicrosoftCodeAnalysisNetAnalyzersVersion>7.0.0-preview1.22102.1</MicrosoftCodeAnalysisNetAnalyzersVersion>
<!-- TODO: Remove pinned compiler version once arcade supplies runtime with a compiler capable of handling !! -->
<MicrosoftNetCompilersToolsetVersion>4.2.0-2.22105.4</MicrosoftNetCompilersToolsetVersion>
<!-- SDK dependencies -->
<MicrosoftDotNetCompatibilityVersion>2.0.0-alpha.1.21525.11</MicrosoftDotNetCompatibilityVersion>
<!-- Arcade dependencies -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,8 @@ internal static class OAVariantLib
* Variant and the types that CLR supports explicitly in the
* CLR Variant class.
*/
internal static Variant ChangeType(Variant source, Type targetClass, short options, CultureInfo culture)
internal static Variant ChangeType(Variant source, Type targetClass!!, short options, CultureInfo culture!!)
{
if (targetClass == null)
throw new ArgumentNullException(nameof(targetClass));
if (culture == null)
throw new ArgumentNullException(nameof(culture));
Variant result = default;
ChangeTypeEx(ref result, ref source,
culture.LCID,
Expand Down
81 changes: 12 additions & 69 deletions src/coreclr/System.Private.CoreLib/src/System/Attribute.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -450,14 +450,8 @@ public static Attribute[] GetCustomAttributes(MemberInfo element, Type attribute
return GetCustomAttributes(element, attributeType, true);
}

public static Attribute[] GetCustomAttributes(MemberInfo element, Type attributeType, bool inherit)
public static Attribute[] GetCustomAttributes(MemberInfo element!!, Type attributeType!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

Expand All @@ -474,11 +468,8 @@ public static Attribute[] GetCustomAttributes(MemberInfo element)
return GetCustomAttributes(element, true);
}

public static Attribute[] GetCustomAttributes(MemberInfo element, bool inherit)
public static Attribute[] GetCustomAttributes(MemberInfo element!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

return element.MemberType switch
{
MemberTypes.Property => InternalGetCustomAttributes((PropertyInfo)element, typeof(Attribute), inherit),
Expand All @@ -492,15 +483,9 @@ public static bool IsDefined(MemberInfo element, Type attributeType)
return IsDefined(element, attributeType, true);
}

public static bool IsDefined(MemberInfo element, Type attributeType, bool inherit)
public static bool IsDefined(MemberInfo element!!, Type attributeType!!, bool inherit)
{
// Returns true if a custom attribute subclass of attributeType class/interface with inheritance walk
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

Expand Down Expand Up @@ -543,14 +528,8 @@ public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attrib
return GetCustomAttributes(element, attributeType, true);
}

public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attributeType, bool inherit)
public static Attribute[] GetCustomAttributes(ParameterInfo element!!, Type attributeType!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

Expand All @@ -565,11 +544,8 @@ public static Attribute[] GetCustomAttributes(ParameterInfo element, Type attrib
return (element.GetCustomAttributes(attributeType, inherit) as Attribute[])!;
}

public static Attribute[] GetCustomAttributes(ParameterInfo element, bool inherit)
public static Attribute[] GetCustomAttributes(ParameterInfo element!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

if (element.Member == null)
throw new ArgumentException(SR.Argument_InvalidParameterInfo, nameof(element));

Expand All @@ -586,14 +562,9 @@ public static bool IsDefined(ParameterInfo element, Type attributeType)
return IsDefined(element, attributeType, true);
}

public static bool IsDefined(ParameterInfo element, Type attributeType, bool inherit)
public static bool IsDefined(ParameterInfo element!!, Type attributeType!!, bool inherit)
{
// Returns true is a custom attribute subclass of attributeType class/interface with inheritance walk
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
Expand Down Expand Up @@ -653,22 +624,13 @@ public static Attribute[] GetCustomAttributes(Module element)
return GetCustomAttributes(element, true);
}

public static Attribute[] GetCustomAttributes(Module element, bool inherit)
public static Attribute[] GetCustomAttributes(Module element!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
}

public static Attribute[] GetCustomAttributes(Module element, Type attributeType, bool inherit)
public static Attribute[] GetCustomAttributes(Module element!!, Type attributeType!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

Expand All @@ -680,14 +642,9 @@ public static bool IsDefined(Module element, Type attributeType)
return IsDefined(element, attributeType, false);
}

public static bool IsDefined(Module element, Type attributeType, bool inherit)
public static bool IsDefined(Module element!!, Type attributeType!!, bool inherit)
{
// Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
Expand Down Expand Up @@ -723,14 +680,8 @@ public static Attribute[] GetCustomAttributes(Assembly element, Type attributeTy
return GetCustomAttributes(element, attributeType, true);
}

public static Attribute[] GetCustomAttributes(Assembly element, Type attributeType, bool inherit)
public static Attribute[] GetCustomAttributes(Assembly element!!, Type attributeType!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);

Expand All @@ -742,11 +693,8 @@ public static Attribute[] GetCustomAttributes(Assembly element)
return GetCustomAttributes(element, true);
}

public static Attribute[] GetCustomAttributes(Assembly element, bool inherit)
public static Attribute[] GetCustomAttributes(Assembly element!!, bool inherit)
{
if (element == null)
throw new ArgumentNullException(nameof(element));

return (Attribute[])element.GetCustomAttributes(typeof(Attribute), inherit);
}

Expand All @@ -755,14 +703,9 @@ public static bool IsDefined(Assembly element, Type attributeType)
return IsDefined(element, attributeType, true);
}

public static bool IsDefined(Assembly element, Type attributeType, bool inherit)
public static bool IsDefined(Assembly element!!, Type attributeType!!, bool inherit)
{
// Returns true is a custom attribute subclass of attributeType class/interface with no inheritance walk
if (element == null)
throw new ArgumentNullException(nameof(element));

if (attributeType == null)
throw new ArgumentNullException(nameof(attributeType));

if (!attributeType.IsSubclassOf(typeof(Attribute)) && attributeType != typeof(Attribute))
throw new ArgumentException(SR.Argument_MustHaveAttributeBaseClass);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ IEnumerator IEnumerable.GetEnumerator()

// ICollection members

public void CopyTo(Array array, int index)
public void CopyTo(Array array!!, int index)
{
if (array == null)
throw new ArgumentNullException(nameof(array));

if (array.Rank != 1)
throw new ArgumentException(SR.Arg_RankMultiDimNotSupported);

Expand All @@ -58,23 +55,14 @@ public void CopyTo(Array array, int index)

// IDictionary members

public object? this[object key]
public object? this[object key!!]
{
get
{
if (key == null)
{
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
}
return null;
}
set
{
if (key == null)
{
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
}

if (!key.GetType().IsSerializable)
throw new ArgumentException(SR.Argument_NotSerializable, nameof(key));

Expand All @@ -94,13 +82,8 @@ public bool Contains(object key)
return false;
}

public void Add(object key, object? value)
public void Add(object key!!, object? value)
{
if (key == null)
{
throw new ArgumentNullException(nameof(key), SR.ArgumentNull_Key);
}

if (!key.GetType().IsSerializable)
throw new ArgumentException(SR.Argument_NotSerializable, nameof(key));

Expand Down
45 changes: 6 additions & 39 deletions src/coreclr/System.Private.CoreLib/src/System/Delegate.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,8 @@ public abstract partial class Delegate : ICloneable, ISerializable
// This constructor is called from the class generated by the
// compiler generated code
[RequiresUnreferencedCode("The target method might be removed")]
protected Delegate(object target, string method)
protected Delegate(object target!!, string method!!)
{
if (target == null)
throw new ArgumentNullException(nameof(target));

if (method == null)
throw new ArgumentNullException(nameof(method));

// This API existed in v1/v1.1 and only expected to create closed
// instance delegates. Constrain the call to BindToMethodName to
// such and don't allow relaxed signature matching (which could make
Expand All @@ -57,17 +51,10 @@ protected Delegate(object target, string method)
// This constructor is called from a class to generate a
// delegate based upon a static method name and the Type object
// for the class defining the method.
protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method)
protected Delegate([DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target!!, string method!!)
{
if (target == null)
throw new ArgumentNullException(nameof(target));

if (target.ContainsGenericParameters)
throw new ArgumentException(SR.Arg_UnboundGenParam, nameof(target));

if (method == null)
throw new ArgumentNullException(nameof(method));

if (!(target is RuntimeType rtTarget))
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(target));

Expand Down Expand Up @@ -220,15 +207,8 @@ protected virtual MethodInfo GetMethodImpl()

// V1 API.
[RequiresUnreferencedCode("The target method might be removed")]
public static Delegate? CreateDelegate(Type type, object target, string method, bool ignoreCase, bool throwOnBindFailure)
public static Delegate? CreateDelegate(Type type!!, object target!!, string method!!, bool ignoreCase, bool throwOnBindFailure)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
if (target == null)
throw new ArgumentNullException(nameof(target));
if (method == null)
throw new ArgumentNullException(nameof(method));

if (!(type is RuntimeType rtType))
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
if (!rtType.IsDelegate())
Expand Down Expand Up @@ -258,17 +238,10 @@ protected virtual MethodInfo GetMethodImpl()
}

// V1 API.
public static Delegate? CreateDelegate(Type type, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target, string method, bool ignoreCase, bool throwOnBindFailure)
public static Delegate? CreateDelegate(Type type!!, [DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)] Type target!!, string method!!, bool ignoreCase, bool throwOnBindFailure)
{
if (type == null)
throw new ArgumentNullException(nameof(type));
if (target == null)
throw new ArgumentNullException(nameof(target));
if (target.ContainsGenericParameters)
throw new ArgumentException(SR.Arg_UnboundGenParam, nameof(target));
if (method == null)
throw new ArgumentNullException(nameof(method));

if (!(type is RuntimeType rtType))
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
if (!(target is RuntimeType rtTarget))
Expand Down Expand Up @@ -297,13 +270,9 @@ protected virtual MethodInfo GetMethodImpl()
}

// V1 API.
public static Delegate? CreateDelegate(Type type, MethodInfo method, bool throwOnBindFailure)
public static Delegate? CreateDelegate(Type type!!, MethodInfo method!!, bool throwOnBindFailure)
{
// Validate the parameters.
if (type == null)
throw new ArgumentNullException(nameof(type));
if (method == null)
throw new ArgumentNullException(nameof(method));

if (!(type is RuntimeType rtType))
throw new ArgumentException(SR.Argument_MustBeRuntimeType, nameof(type));
Expand Down Expand Up @@ -374,11 +343,9 @@ protected virtual MethodInfo GetMethodImpl()
//

// V2 internal API.
internal static Delegate CreateDelegateNoSecurityCheck(Type type, object? target, RuntimeMethodHandle method)
internal static Delegate CreateDelegateNoSecurityCheck(Type type!!, object? target, RuntimeMethodHandle method)
{
// Validate the parameters.
if (type == null)
throw new ArgumentNullException(nameof(type));

if (method.IsNullHandle())
throw new ArgumentNullException(nameof(method));
Expand Down
Loading