Skip to content

Commit d85ec4e

Browse files
authored
Enable set of nullability checks in NativeAOT CoreLib (#64730)
Contributes to dotnet/runtimelab#106
1 parent 2b862d4 commit d85ec4e

File tree

18 files changed

+27
-26
lines changed

18 files changed

+27
-26
lines changed

src/coreclr/nativeaot/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
<NoWarn>$(NoWarn),0419,0649,CA2249,CA1830</NoWarn>
3232

3333
<!-- Disable nullability-related warnings -->
34-
<NoWarn>$(NoWarn);CS8600;CS8602;CS8603;CS8604;CS8610;CS8618;CS8620;CS8625;CS8632;CS8765</NoWarn>
34+
<NoWarn>$(NoWarn);CS8600;CS8602;CS8603;CS8604;CS8618;CS8625;CS8632;CS8765</NoWarn>
3535

3636
<!-- we should just fix -->
3737
<NoWarn>$(NoWarn);CA1810;CA1823;CA1825;CA2208;SA1129;SA1205;SA1400;SA1517</NoWarn>

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Reflection/Augments/ReflectionAugments.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public abstract object ActivatorCreateInstance(
138138
Type type, bool nonPublic);
139139
public abstract object ActivatorCreateInstance(
140140
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.PublicConstructors | DynamicallyAccessedMemberTypes.NonPublicConstructors)]
141-
Type type, BindingFlags bindingAttr, Binder binder, object[] args, CultureInfo culture, object[] activationAttributes);
141+
Type type, BindingFlags bindingAttr, Binder? binder, object?[]? args, CultureInfo? culture, object?[]? activationAttributes);
142142

143143
// V2 api: Creates open or closed delegates to static or instance methods - relaxed signature checking allowed.
144144
public abstract Delegate CreateDelegate(Type type, object? firstArgument, MethodInfo method, bool throwOnBindFailure);

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/Augments/ReflectionExecutionDomainCallbacks.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ namespace Internal.Runtime.Augments
2626
public abstract class ReflectionExecutionDomainCallbacks
2727
{
2828
// Api's that are exposed in System.Runtime but are really reflection apis.
29-
public abstract Type GetType(string typeName, Func<AssemblyName, Assembly>? assemblyResolver, Func<Assembly, string, bool, Type>? typeResolver, bool throwOnError, bool ignoreCase, string defaultAssembly);
29+
public abstract Type GetType(string typeName, Func<AssemblyName, Assembly?>? assemblyResolver, Func<Assembly?, string, bool, Type?>? typeResolver, bool throwOnError, bool ignoreCase, string defaultAssembly);
3030

3131
public abstract IntPtr TryGetStaticClassConstructionContext(RuntimeTypeHandle runtimeTypeHandle);
3232

src/coreclr/nativeaot/System.Private.CoreLib/src/Internal/Runtime/CompilerHelpers/ReflectionHelpers.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static Type GetType(string typeName, string callingAssemblyName, bool thr
2222

2323
// This entry is used to implement Type.GetType()'s ability to detect the calling assembly and use it as
2424
// a default assembly name.
25-
public static Type ExtensibleGetType(string typeName, string callingAssemblyName, Func<AssemblyName, Assembly> assemblyResolver, Func<Assembly, string, bool, Type> typeResolver, bool throwOnError, bool ignoreCase)
25+
public static Type ExtensibleGetType(string typeName, string callingAssemblyName, Func<AssemblyName, Assembly?> assemblyResolver, Func<Assembly?, string, bool, Type?>? typeResolver, bool throwOnError, bool ignoreCase)
2626
{
2727
return RuntimeAugments.Callbacks.GetType(typeName, assemblyResolver, typeResolver, throwOnError, ignoreCase, callingAssemblyName);
2828
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Activator.CoreRT.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,15 +127,15 @@ public static ObjectHandle CreateInstance(string assemblyName,
127127
bool ignoreCase,
128128
BindingFlags bindingAttr,
129129
Binder? binder,
130-
object[]? args,
130+
object?[]? args,
131131
CultureInfo? culture,
132-
object[]? activationAttributes)
132+
object?[]? activationAttributes)
133133
{
134134
throw new PlatformNotSupportedException(); // https://github.com/dotnet/corefx/issues/30845
135135
}
136136

137137
[RequiresUnreferencedCode("Type and its constructor could be removed")]
138-
public static ObjectHandle CreateInstance(string assemblyName, string typeName, object[]? activationAttributes)
138+
public static ObjectHandle CreateInstance(string assemblyName, string typeName, object?[]? activationAttributes)
139139
{
140140
throw new PlatformNotSupportedException(); // https://github.com/dotnet/corefx/issues/30845
141141
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Delegate.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,12 @@ internal bool IsDynamicDelegate()
278278
}
279279

280280
[DebuggerGuidedStepThroughAttribute]
281-
protected virtual object DynamicInvokeImpl(object[]? args)
281+
protected virtual object DynamicInvokeImpl(object?[]? args)
282282
{
283283
if (IsDynamicDelegate())
284284
{
285285
// DynamicDelegate case
286-
object result = ((Func<object[]?, object>)m_helperObject)(args);
286+
object result = ((Func<object?[]?, object>)m_helperObject)(args);
287287
DebugAnnotations.PreviousCallContainsDebuggerStepInCode();
288288
return result;
289289
}
@@ -378,7 +378,7 @@ internal static bool InternalEqualTypes(object a, object b)
378378

379379
// Returns a new delegate of the specified type whose implementation is provied by the
380380
// provided delegate.
381-
internal static Delegate CreateObjectArrayDelegate(Type t, Func<object[], object> handler)
381+
internal static Delegate CreateObjectArrayDelegate(Type t, Func<object?[], object?> handler)
382382
{
383383
EETypePtr delegateEEType;
384384
if (!t.TryGetEEType(out delegateEEType))

src/coreclr/nativeaot/System.Private.CoreLib/src/System/InvokeUtils.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ internal static unsafe object CallDynamicInvokeMethod(
352352
IntPtr dynamicInvokeHelperMethod,
353353
IntPtr dynamicInvokeHelperGenericDictionary,
354354
object targetMethodOrDelegate,
355-
object[]? parameters,
355+
object?[]? parameters,
356356
BinderBundle? binderBundle,
357357
bool wrapInTargetInvocationException,
358358
bool methodToCallIsThisCall = true)
@@ -509,7 +509,7 @@ internal static ref IntPtr DynamicInvokeParamHelperRef(ref ArgSetupState argSetu
509509
}
510510
}
511511

512-
internal static object DynamicInvokeBoxedValuetypeReturn(out DynamicInvokeParamLookupType paramLookupType, object? boxedValuetype, object[]? parameters, int index, RuntimeTypeHandle type, DynamicInvokeParamType paramType, ref object[] nullableCopyBackObjects)
512+
internal static object DynamicInvokeBoxedValuetypeReturn(out DynamicInvokeParamLookupType paramLookupType, object? boxedValuetype, object?[]? parameters, int index, RuntimeTypeHandle type, DynamicInvokeParamType paramType, ref object[] nullableCopyBackObjects)
513513
{
514514
object finalObjectToReturn = boxedValuetype;
515515
EETypePtr eeType = type.ToEETypePtr();

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/ConstructorBuilder.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ public override ParameterInfo[] GetParameters()
114114
return default;
115115
}
116116

117-
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
117+
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
118118
{
119119
return default;
120120
}
121121

122-
public override object Invoke(BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
122+
public override object Invoke(BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
123123
{
124124
return default;
125125
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/DynamicMethod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ public override ParameterInfo[] GetParameters()
194194
return default;
195195
}
196196

197-
public override object Invoke(object obj, BindingFlags invokeAttr, Binder binder, object[] parameters, CultureInfo culture)
197+
public override object? Invoke(object? obj, BindingFlags invokeAttr, Binder? binder, object?[]? parameters, CultureInfo? culture)
198198
{
199199
return default;
200200
}

src/coreclr/nativeaot/System.Private.CoreLib/src/System/Reflection/Emit/EnumBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ protected override bool HasElementTypeImpl()
280280
}
281281

282282
[DynamicallyAccessedMembers(DynamicallyAccessedMemberTypes.All)]
283-
public override object InvokeMember(string name, BindingFlags invokeAttr, Binder binder, object target, object[] args, ParameterModifier[] modifiers, System.Globalization.CultureInfo culture, string[] namedParameters)
283+
public override object? InvokeMember(string name, BindingFlags invokeAttr, Binder? binder, object? target, object?[]? args, ParameterModifier[]? modifiers, Globalization.CultureInfo? culture, string[]? namedParameters)
284284
{
285285
return default;
286286
}

0 commit comments

Comments
 (0)