mirror of
https://github.com/github/codeql.git
synced 2026-04-22 07:15:15 +02:00
Merge pull request #4314 from tamasvajk/feature/switch-case-expr
C#: Fix switch case expression types
This commit is contained in:
@@ -18,10 +18,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
protected override void PopulateExpression(TextWriter trapFile)
|
||||
{
|
||||
SwitchedExpr = Expression.Create(cx, Syntax.GoverningExpression, this, -1);
|
||||
int child = 0;
|
||||
foreach (var arm in Syntax.Arms)
|
||||
for (var i = 0; i < Syntax.Arms.Count; i++)
|
||||
{
|
||||
new SwitchCase(cx, arm, this, child++);
|
||||
new SwitchCase(cx, Syntax.Arms[i], this, i);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,7 +28,9 @@ namespace Semmle.Extraction.CSharp.Entities.Expressions
|
||||
class SwitchCase : Expression
|
||||
{
|
||||
internal SwitchCase(Context cx, SwitchExpressionArmSyntax arm, Switch parent, int child) :
|
||||
base(new ExpressionInfo(cx, parent.SwitchedExpr.Type, cx.Create(arm.GetLocation()), ExprKind.SWITCH_CASE, parent, child, false, null))
|
||||
base(new ExpressionInfo(
|
||||
cx, Entities.Type.Create(cx, cx.GetType(arm.Expression)), cx.Create(arm.GetLocation()),
|
||||
ExprKind.SWITCH_CASE, parent, child, false, null))
|
||||
{
|
||||
cx.CreatePattern(arm.Pattern, this, 0);
|
||||
if (arm.WhenClause is WhenClauseSyntax when)
|
||||
|
||||
@@ -397,8 +397,14 @@
|
||||
| Guards.cs:276:16:276:16 | access to parameter o | match access to type Action<Object> | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:276:16:276:16 | access to parameter o | match null | Guards.cs:276:16:276:16 | access to parameter o | null |
|
||||
| Guards.cs:276:16:276:16 | access to parameter o | non-match null | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:278:13:279:28 | ... => ... | true | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:280:13:281:28 | ... => ... | true | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:281:17:281:17 | access to local variable a | non-null | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:281:17:281:17 | access to local variable a | null | Guards.cs:276:16:276:16 | access to parameter o | null |
|
||||
| Guards.cs:282:13:283:28 | ... => ... | true | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:284:13:285:28 | ... => ... | false | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:284:13:285:28 | ... => ... | true | Guards.cs:276:16:276:16 | access to parameter o | null |
|
||||
| Guards.cs:286:13:287:28 | ... => ... | true | Guards.cs:276:16:276:16 | access to parameter o | non-null |
|
||||
| Guards.cs:296:16:296:17 | access to local variable b2 | match true | Guards.cs:294:13:294:14 | access to parameter b1 | false |
|
||||
| Guards.cs:296:16:296:17 | access to local variable b2 | match true | Guards.cs:296:16:296:17 | access to local variable b2 | true |
|
||||
| Guards.cs:308:16:308:17 | access to local variable b2 | match true | Guards.cs:306:13:306:14 | access to parameter b1 | true |
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
| patterns.cs:101:34:101:40 | "large" | String |
|
||||
| patterns.cs:102:18:102:24 | "small" | String |
|
||||
| patterns.cs:110:22:110:26 | (..., ...) | (Int32,Int32) |
|
||||
| patterns.cs:111:22:111:26 | (..., ...) | (Int32,Int32) |
|
||||
| patterns.cs:117:27:117:33 | (..., ...) | (Int32,Int32) |
|
||||
| patterns.cs:118:28:118:34 | (..., ...) | (Int32,Int32) |
|
||||
| patterns.cs:119:33:119:38 | (..., ...) | (Int32,Int32) |
|
||||
| patterns.cs:128:49:128:49 | 0 | Int32 |
|
||||
| patterns.cs:129:38:129:38 | 1 | Int32 |
|
||||
| patterns.cs:130:23:130:23 | 2 | Int32 |
|
||||
| patterns.cs:131:27:131:27 | 3 | Int32 |
|
||||
| patterns.cs:138:22:138:50 | throw ... | null |
|
||||
| patterns.cs:139:22:139:22 | 3 | Int32 |
|
||||
| patterns.cs:140:42:140:42 | 4 | Int32 |
|
||||
| patterns.cs:141:29:141:29 | 5 | Int32 |
|
||||
| patterns.cs:142:41:142:41 | 6 | Int32 |
|
||||
@@ -0,0 +1,4 @@
|
||||
import csharp
|
||||
|
||||
from SwitchCaseExpr case
|
||||
select case.getBody(), case.getType().toString()
|
||||
Reference in New Issue
Block a user