Skip to content

Commit

Permalink
S3655: Static properties named Value
Browse files Browse the repository at this point in the history
  • Loading branch information
antonioaversa committed Mar 28, 2023
1 parent 5c31e36 commit b3538ce
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ protected override ProgramState PreProcessSimple(SymbolicContext context)
if (operationInstance.Kind == OperationKindEx.PropertyReference
&& operationInstance.ToPropertyReference() is var reference
&& reference.Property.Name == nameof(Nullable<int>.Value)
&& reference.Instance.Type.IsNullableValueType()
&& reference.Instance is { } instance
&& instance.Type.IsNullableValueType()
&& context.HasConstraint(reference.Instance, ObjectConstraint.Null))
{
ReportIssue(reference.Instance, reference.Instance.Syntax.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ void Basics(MaybeInt i)
}
}

namespace TypeWithValueProperty
namespace TypeWithValueInstanceProperty
{
class Test
{
Expand Down Expand Up @@ -971,3 +971,29 @@ struct StructWithValuePropertyAndCastOperators
}
}

namespace TypeWithValueStaticProperty
{
class Test
{
void Basics()
{
_ = AClassWithStaticValueProperty.Value; // Compliant, not on nullable value type
_ = AClassWithStaticValueProperty.Value.Value; // Compliant
_ = AClassWithStaticValueProperty.Value.Value.InstanceProperty; // Compliant
_ = AClassWithStaticValueProperty.Value.Value.InstanceProperty.Value; // Compliant
_ = new AClassWithInstanceValueProperty().Value; // Compliant
}
}

class AClassWithStaticValueProperty
{
public AClassWithInstanceValueProperty InstanceProperty => new AClassWithInstanceValueProperty();

public static AClassWithInstanceValueProperty Value => new AClassWithInstanceValueProperty();
}

class AClassWithInstanceValueProperty
{
public AClassWithStaticValueProperty Value => new AClassWithStaticValueProperty();
}
}

0 comments on commit b3538ce

Please sign in to comment.