Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit bcd8dca

Browse files
committed
C#: When creating conditionally accessed expressions, use the typeinfo from the conditional expression to ensure correct flow state and type nullability.
1 parent 85c9459 commit bcd8dca

2 files changed

Lines changed: 4 additions & 3 deletions

File tree

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expression.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ abstract class Expression<SyntaxNode> : Expression
292292
protected Expression(ExpressionNodeInfo info)
293293
: base(info)
294294
{
295-
Syntax = (SyntaxNode)info.Node;
295+
Syntax = (SyntaxNode)info.Node;
296296
}
297297

298298
/// <summary>
@@ -374,7 +374,8 @@ class ExpressionInfo : IExpressionInfo
374374
public bool IsCompilerGenerated { get; }
375375
public string ExprValue { get; }
376376

377-
public ExpressionInfo(Context cx, AnnotatedType type, Extraction.Entities.Location location, ExprKind kind, IExpressionParentEntity parent, int child, bool isCompilerGenerated, string value)
377+
public ExpressionInfo(Context cx, AnnotatedType type, Extraction.Entities.Location location, ExprKind kind,
378+
IExpressionParentEntity parent, int child, bool isCompilerGenerated, string value)
378379
{
379380
Context = cx;
380381
Type = type;

csharp/extractor/Semmle.Extraction.CSharp/Entities/Expressions/MemberAccess.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private MemberAccess(ExpressionNodeInfo info, ExpressionSyntax qualifier, ISymbo
3030
public static Expression Create(ExpressionNodeInfo info, ConditionalAccessExpressionSyntax node) =>
3131
// The qualifier is located by walking the syntax tree.
3232
// `node.WhenNotNull` will contain a MemberBindingExpressionSyntax, calling the method below.
33-
Create(info.Context, node.WhenNotNull, info.Parent, info.Child);
33+
CreateFromNode(new ExpressionNodeInfo(info.Context, node.WhenNotNull, info.Parent, info.Child, info.TypeInfo));
3434

3535
public static Expression Create(ExpressionNodeInfo info, MemberBindingExpressionSyntax node)
3636
{

0 commit comments

Comments
 (0)