Skip to content

Commit

Permalink
Fix code-cracker#774 - ignore pointer declaration
Browse files Browse the repository at this point in the history
  • Loading branch information
carloscds authored and giggio committed Sep 6, 2016
1 parent 160d12b commit 4dc4707
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ private static void AnalyzeNode(SyntaxNodeAnalysisContext context)
var localDeclaration = (LocalDeclarationStatementSyntax)context.Node;
var semanticModel = context.SemanticModel;

if (localDeclaration.GetType().IsPointer) return;

if (!localDeclaration.IsConst
&& IsDeclarationConstFriendly(localDeclaration, semanticModel)
&& AreVariablesOnlyWrittenInsideDeclaration(localDeclaration, semanticModel) )
Expand All @@ -61,6 +63,7 @@ static bool IsDeclarationConstFriendly(LocalDeclarationStatementSyntax declarati
// if reference type, value is null?
var variableTypeName = declaration.Declaration.Type;
var variableType = semanticModel.GetTypeInfo(variableTypeName).ConvertedType;
if (variableType.TypeKind == TypeKind.Pointer) return false;
if (variableType.IsReferenceType && variableType.SpecialType != SpecialType.System_String && constantValue.Value != null) return false;

// nullable?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public async Task IgnoresVariablesThatChangesValueOutsideDeclaration()
await VerifyCSharpHasNoDiagnosticsAsync(test);
}

public async Task IgnoresPointerDeclarations()
{
var test = @"void* value = null;".WrapInCSharpMethod();

await VerifyCSharpHasNoDiagnosticsAsync(test);
}

[Fact]
public async Task CreateDiagnosticsWhenAssigningAPotentialConstant()
{
Expand Down

0 comments on commit 4dc4707

Please sign in to comment.