Skip to content

Commit

Permalink
Merge pull request #5 from xiaoxiao921/main
Browse files Browse the repository at this point in the history
Fix a case for harmony non-ref parameter analyzer and null ref exception for publicized accesses analyzer
  • Loading branch information
ghorsington authored Jan 24, 2022
2 parents e3dabd1 + 04154ea commit 141db9e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<PropertyGroup>
<PackageId>BepInEx.Analyzers</PackageId>
<PackageVersion>1.0.7</PackageVersion>
<PackageVersion>1.0.8</PackageVersion>
<Authors>BepInEx</Authors>
<PackageProjectUrl>https://github.com/BepInEx/BepInEx.Analyzers</PackageProjectUrl>
<PackageIconUrl>https://avatars2.githubusercontent.com/u/39589027</PackageIconUrl>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ private void AnalyzeSimpleMemberAccess(SyntaxNodeAnalysisContext context)
{
var memberAccess = (MemberAccessExpressionSyntax)context.Node;
var symbol = context.SemanticModel.GetSymbolInfo(memberAccess.Name, context.CancellationToken).Symbol;

if (symbol == null)
return;

Expand All @@ -62,12 +62,12 @@ private void AnalyzeSimpleMemberAccess(SyntaxNodeAnalysisContext context)
var propertyUsage = context.Node.GetPropertyUsage();
if (propertyUsage == Extensions.PropertyUsage.Get || propertyUsage == Extensions.PropertyUsage.GetAndSet)
{
var getMethodPublicizedAttribute = propertySymbol.GetMethod.GetAttribute(PublicizedAttributeName);
var getMethodPublicizedAttribute = propertySymbol.GetMethod?.GetAttribute(PublicizedAttributeName);
Check(getMethodPublicizedAttribute, symbol, context, memberAccess);
}
else
{
var setMethodPublicizedAttribute = propertySymbol.SetMethod.GetAttribute(PublicizedAttributeName);
var setMethodPublicizedAttribute = propertySymbol.SetMethod?.GetAttribute(PublicizedAttributeName);
Check(setMethodPublicizedAttribute, symbol, context, memberAccess);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,17 @@ private static void CheckExpressionSyntaxes(SyntaxNodeAnalysisContext context, M
foreach (var parameter in method.ParameterList.Parameters)
{
// If parameter is a reference type and is not a literal assignment no warning needed
if (context.SemanticModel.GetDeclaredSymbol(parameter, context.CancellationToken).Type.IsReferenceType)
var parameterSymbol = context.SemanticModel.GetDeclaredSymbol(parameter, context.CancellationToken);
if (parameterSymbol.Type.IsReferenceType)
{
if (!(expressionSyntaxes[i] is AssignmentExpressionSyntax assignment))
{
continue;
}
}

// TODO : Looking through the ToString() and "ref" is not the cleanest
var parameterSplit = parameter.ToString().Split(' ');
if (parameterSplit.Any(s => s == varNames[i]) && !parameterSplit.Any(s => s == "ref" || s == "out"))
var parameterName = parameterSymbol.Name;
if (parameterSymbol.RefKind == RefKind.None && parameterName == varNames[i])
{
context.ReportDiagnostic(Diagnostic.Create(Rule, expressionSyntaxes[i].GetLocation(), expressionSyntaxes[i].ToString()));
}
Expand Down

0 comments on commit 141db9e

Please sign in to comment.