Skip to content

C#: Minor extractor fixes #393

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

Merged
merged 3 commits into from
Nov 16, 2018

Conversation

calumgrant
Copy link
Contributor

@calumgrant calumgrant commented Oct 31, 2018

This fixes two small issues that were causing messages in csharp.log.

  1. Local variables were always expecting to be used in a "tagged" context, but this failed when they were declared in lambdas in fields properties. Change this to "optionally tagged" instead.
  2. The dynamic typename was not extracted.

@calumgrant calumgrant added the C# label Oct 31, 2018
@calumgrant calumgrant requested review from hvitved and jf205 October 31, 2018 14:13
@calumgrant calumgrant requested a review from a team as a code owner October 31, 2018 14:13
Copy link
Contributor

@hvitved hvitved left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One question, otherwise LGTM.

@@ -90,6 +90,6 @@ class LocalVariableFactory : ICachedEntityFactory<(ISymbol, Expression, bool, Ex
new LocalVariable(cx, init.Item1, init.Item2, init.Item3, init.Item4);
}

public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.NeedsLabel;
public override TrapStackBehaviour TrapStackBehaviour => TrapStackBehaviour.OptionalLabel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you elaborate on why this is needed? I wonder because the Field entity sets TrapStackBehaviour.PushLabel, which I assume happens before extracting the initializer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is because fields don't use the tag stack. Most of the time, local variables are declared inside methods, or in lambdas in methods, so the tag stack is non-empty. However, a local variable can be declared inside a lambda which is used as an initializer to a field, e.g. here.

In those cases, there is no surrounding method, and therefore the tagstack is empty. This was causing the tagstack unexpectedly empty messages in csharp.log.

Changing the behaviour to OptionalLabel removes that warning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is because fields don't use the tag stack

Then what does my link from above mean, I must have misunderstood something? (https://github.com/Semmle/ql/blob/master/csharp/extractor/Semmle.Extraction.CSharp/Entities/Field.cs#L99)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reverted this change because it was the wrong fix. It actually turned out that the erroneous case was a property with an expression body, so I changed the trap stack behaviour of properties to PushesLabel.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thanks for investigating this!

Copy link
Contributor

@jf205 jf205 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change note LGTM

@calumgrant calumgrant force-pushed the cs/extractor/dynamic-type-name branch from 1ac5660 to 9eed758 Compare November 15, 2018 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants