Skip to content

Commit

Permalink
nullref warning fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
jakubmisek committed Jun 2, 2024
1 parent 06f5b3f commit 7ea7715
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
16 changes: 12 additions & 4 deletions src/Peachpie.Runtime/Reflection/PhpPropertyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,8 +275,9 @@ public override FieldAttributes Attributes
{
get
{
var getter = Property.GetMethod ?? throw new InvalidOperationException($"getter is null");
var flags = (FieldAttributes)0;
var attr = Property.GetMethod.Attributes;
var attr = getter.Attributes;

switch (attr & MethodAttributes.MemberAccessMask)
{
Expand Down Expand Up @@ -313,9 +314,16 @@ public override FieldAttributes Attributes

public override Expression Bind(Expression ctx, Expression target)
{
return Expression.Property(
Property.GetMethod.IsStatic ? null : target,
Property);
var getter = Property.GetMethod;
if (getter != null)
{
return Expression.Property(
getter.IsStatic ? null : target,
Property
);
}

throw new InvalidOperationException($"Property '{ContainingType.Name}::{Property.Name}' does not have a getter.");
}
}

Expand Down
10 changes: 6 additions & 4 deletions src/Peachpie.Runtime/Reflection/PhpRoutineInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,16 @@ internal class PhpRoutineInfo : RoutineInfo

public override int GetHashCode() => _handle.GetHashCode();

public override MethodInfo[] Methods => new[] { (MethodInfo)MethodBase.GetMethodFromHandle(_handle) };
public override MethodInfo[] Methods => new[] { GetMethodFromHandle(_handle) };

public override PhpTypeInfo? DeclaringType => null;

public override PhpCallable PhpCallable => _lazyDelegate ?? BindDelegate();

PhpCallable BindDelegate() => _lazyDelegate = Dynamic.BinderHelpers.BindToPhpCallable(Methods);

private static MethodInfo/*!*/GetMethodFromHandle(RuntimeMethodHandle handle) => (MethodInfo)(MethodBase.GetMethodFromHandle(handle) ?? throw new InvalidOperationException());

internal static PhpRoutineInfo Create(string name, RuntimeMethodHandle handle, params RuntimeMethodHandle[] overloads)
{
return (overloads.Length == 0)
Expand Down Expand Up @@ -162,10 +164,10 @@ public override MethodInfo[] Methods
// [Method] + Overloads

var methods = new MethodInfo[1 + overloads.Length];
methods[0] = (MethodInfo)MethodBase.GetMethodFromHandle(Handle);
methods[0] = GetMethodFromHandle(Handle);
for (int i = 0; i < overloads.Length; i++)
{
methods[1 + i] = (MethodInfo)MethodBase.GetMethodFromHandle(overloads[i]);
methods[1 + i] = GetMethodFromHandle(overloads[i]);
}

//
Expand Down Expand Up @@ -203,7 +205,7 @@ internal class DelegateRoutineInfo : RoutineInfo

public override PhpTypeInfo? DeclaringType => null;

internal override object Target => _delegate.Target;
internal override object? Target => _delegate.Target;

public override int GetHashCode() => _delegate.GetHashCode();

Expand Down

0 comments on commit 7ea7715

Please sign in to comment.