Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Potential fix for code scanning alert no. 12: Local scope variable shadows member #344

Merged
merged 1 commit into from
Mar 11, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@
}
}

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location loc, IEntity parent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type type)

Check notice

Code scanning / CodeQL

Local scope variable shadows member Note

Local scope variable 'parent' shadows
TypeMention.parent
.

Copilot Autofix AI 13 days ago

To fix the problem, we need to rename the local variable parent in the Emit method to avoid shadowing the member variable parent. This will make the code clearer and reduce the risk of confusion or bugs. The best way to do this is to choose a new name for the local variable that accurately describes its purpose without conflicting with the member variable name.

In this case, we can rename the local variable parent to parentEntity in the Emit method. This change will be made in the file csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs on line 121 and any other lines within the Emit method that reference this variable.

Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
@@ -120,5 +120,5 @@
 
-        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type type)
+        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parentEntity, Type type)
         {
-            trapFile.type_mention(this, type.TypeRef, parent);
+            trapFile.type_mention(this, type.TypeRef, parentEntity);
             trapFile.type_mention_location(this, Context.CreateLocation(location));
EOF
@@ -120,5 +120,5 @@

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parentEntity, Type type)
{
trapFile.type_mention(this, type.TypeRef, parent);
trapFile.type_mention(this, type.TypeRef, parentEntity);
trapFile.type_mention_location(this, Context.CreateLocation(location));
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options

Check notice

Code scanning / CodeQL

Local scope variable shadows member Note

Local scope variable 'type' shadows
TypeMention.type
.

Copilot Autofix AI 13 days ago

To fix the problem, we need to rename the local variable type in the Emit method to avoid shadowing the member variable type. This will make the code clearer and reduce the risk of errors. The best way to fix this is to choose a new name for the local variable that accurately describes its purpose and does not conflict with any existing member variables.

In this case, we can rename the local variable type to localType in the Emit method. This change will be made in the file csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs on lines 121 and 123.

Suggested changeset 1
csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
--- a/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
+++ b/csharp/extractor/Semmle.Extraction.CSharp/Entities/TypeMention.cs
@@ -120,5 +120,5 @@
 
-        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type type)
+        private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type localType)
         {
-            trapFile.type_mention(this, type.TypeRef, parent);
+            trapFile.type_mention(this, localType.TypeRef, parent);
             trapFile.type_mention_location(this, Context.CreateLocation(location));
EOF
@@ -120,5 +120,5 @@

private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type type)
private void Emit(TextWriter trapFile, Microsoft.CodeAnalysis.Location location, IEntity parent, Type localType)
{
trapFile.type_mention(this, type.TypeRef, parent);
trapFile.type_mention(this, localType.TypeRef, parent);
trapFile.type_mention_location(this, Context.CreateLocation(location));
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
{
trapFile.type_mention(this, type.TypeRef, parent);
trapFile.type_mention_location(this, Context.CreateLocation(loc));
trapFile.type_mention_location(this, Context.CreateLocation(location));
}

public static TypeMention Create(Context cx, TypeSyntax syntax, IEntity parent, Type type, Microsoft.CodeAnalysis.Location? loc = null)
Expand Down
Loading