Skip to content

Commit 9af170f

Browse files
committed
C#: Add BMN test using broken types.
1 parent 5551aeb commit 9af170f

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Broken type without a name.
2+
public class { }
3+
4+
// Legal declaration, but we want don't want to use it.
5+
public class var { }
6+
7+
public class C
8+
{
9+
public string Prop { get; set; }
10+
}
11+
12+
13+
public class Program
14+
{
15+
public static void Main()
16+
{
17+
C x1 = new C();
18+
string y1 = x1.Prop;
19+
20+
var x2 = new C(); // Has type `var` as this overrides the implicitly typed keyword `var`.
21+
var y2 = x2.Prop; // Unknown type as `x2` har type `var`.
22+
23+
C2 x3 = new C2(); // Unknown type.
24+
var y3 = x3.Prop; // Unknown property of unknown type.
25+
26+
string s = x1.Prop + x3.Prop;
27+
}
28+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
| BrokenTypes.cs:2:14:2:13 | call to constructor Object | object | ObjectType |
2+
| BrokenTypes.cs:5:14:5:16 | call to constructor Object | object | ObjectType |
3+
| BrokenTypes.cs:7:14:7:14 | call to constructor Object | object | ObjectType |
4+
| BrokenTypes.cs:13:14:13:20 | call to constructor Object | object | ObjectType |
5+
| BrokenTypes.cs:17:11:17:12 | access to local variable x1 | C | Class |
6+
| BrokenTypes.cs:17:11:17:22 | C x1 = ... | C | Class |
7+
| BrokenTypes.cs:17:16:17:22 | object creation of type C | C | Class |
8+
| BrokenTypes.cs:18:16:18:17 | access to local variable y1 | string | StringType |
9+
| BrokenTypes.cs:18:16:18:27 | String y1 = ... | string | StringType |
10+
| BrokenTypes.cs:18:21:18:22 | access to local variable x1 | C | Class |
11+
| BrokenTypes.cs:18:21:18:27 | access to property Prop | string | StringType |
12+
| BrokenTypes.cs:20:13:20:14 | access to local variable x2 | var | Class |
13+
| BrokenTypes.cs:20:13:20:24 | var x2 = ... | var | Class |
14+
| BrokenTypes.cs:20:18:20:24 | (...) ... | var | Class |
15+
| BrokenTypes.cs:20:18:20:24 | object creation of type C | C | Class |
16+
| BrokenTypes.cs:21:13:21:14 | access to local variable y2 | var | Class |
17+
| BrokenTypes.cs:21:13:21:24 | var y2 = ... | var | Class |
18+
| BrokenTypes.cs:21:18:21:19 | access to local variable x2 | var | Class |
19+
| BrokenTypes.cs:21:18:21:24 | (...) ... | var | Class |
20+
| BrokenTypes.cs:21:18:21:24 | access to property (unknown) | | Class |
21+
| BrokenTypes.cs:23:12:23:13 | access to local variable x3 | <unknown type> | UnknownType |
22+
| BrokenTypes.cs:23:12:23:24 | <unknown type> x3 = ... | <unknown type> | UnknownType |
23+
| BrokenTypes.cs:23:17:23:24 | object creation of type <unknown type> | <unknown type> | UnknownType |
24+
| BrokenTypes.cs:24:13:24:14 | access to local variable y3 | var | Class |
25+
| BrokenTypes.cs:24:13:24:24 | var y3 = ... | var | Class |
26+
| BrokenTypes.cs:24:18:24:19 | access to local variable x3 | <unknown type> | UnknownType |
27+
| BrokenTypes.cs:24:18:24:24 | (...) ... | var | Class |
28+
| BrokenTypes.cs:24:18:24:24 | access to property (unknown) | | Class |
29+
| BrokenTypes.cs:26:16:26:16 | access to local variable s | string | StringType |
30+
| BrokenTypes.cs:26:16:26:36 | String s = ... | string | StringType |
31+
| BrokenTypes.cs:26:20:26:21 | access to local variable x1 | C | Class |
32+
| BrokenTypes.cs:26:20:26:26 | access to property Prop | string | StringType |
33+
| BrokenTypes.cs:26:20:26:36 | (...) ... | string | StringType |
34+
| BrokenTypes.cs:26:20:26:36 | ... + ... | | Class |
35+
| BrokenTypes.cs:26:30:26:31 | access to local variable x3 | <unknown type> | UnknownType |
36+
| BrokenTypes.cs:26:30:26:36 | access to property (unknown) | | Class |
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import csharp
2+
3+
from Expr e, Type t
4+
where e.fromSource() and t = e.getType()
5+
select e, t.toStringWithTypes(), t.getAPrimaryQlClass()
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: --standalone

0 commit comments

Comments
 (0)