-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
C#: Minor extractor fixes #393
Conversation
There was a problem hiding this 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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change note LGTM
1ac5660
to
9eed758
Compare
This fixes two small issues that were causing messages in
csharp.log
.fieldsproperties.Change this to "optionally tagged" instead.dynamic
typename was not extracted.