Skip to content

Commit d3d3cce

Browse files
authored
Merge pull request #18575 from michaelnebel/csharp/overloadresolution
C# 13: Overload resolution priority.
2 parents a54e732 + 340f3c0 commit d3d3cce

16 files changed

+1777
-1602
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* C# 13: Added support for the overload resolution priority attribute (`OverloadResolutionPriority`). Usages of the attribute and the corresponding priority can be found using the QL class `SystemRuntimeCompilerServicesOverloadResolutionPriorityAttribute`.

csharp/ql/lib/semmle/code/csharp/Attribute.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ class Attribute extends TopLevelExprParent, @attribute {
6969
attributes(this, _, getTypeRef(result), _)
7070
}
7171

72+
/** Gets the namespace containing the attribute type declaration. */
73+
Namespace getNamespace() { result = this.getType().getNamespace() }
74+
7275
/** Gets the element that this attribute is attached to. */
7376
Attributable getTarget() { attributes(this, _, _, result) }
7477

csharp/ql/lib/semmle/code/csharp/frameworks/system/runtime/CompilerServices.qll

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,25 @@ class SystemRuntimeCompilerServicesConfiguredTaskAwaitableTConfiguredTaskAwaiter
7474
/** An attribute of type `System.Runtime.CompilerServices.InlineArrayAttribute`. */
7575
class SystemRuntimeCompilerServicesInlineArrayAttribute extends Attribute {
7676
SystemRuntimeCompilerServicesInlineArrayAttribute() {
77-
this.getType().hasFullyQualifiedName("System.Runtime.CompilerServices", "InlineArrayAttribute")
77+
this.getNamespace() instanceof SystemRuntimeCompilerServicesNamespace and
78+
this.getType().hasName("InlineArrayAttribute")
7879
}
7980

8081
/**
8182
* Gets the length of the inline array.
8283
*/
8384
int getLength() { result = this.getConstructorArgument(0).getValue().toInt() }
8485
}
86+
87+
/** An attribute of type `System.Runtime.CompilerServices.OverloadResolutionPriority`. */
88+
class SystemRuntimeCompilerServicesOverloadResolutionPriorityAttribute extends Attribute {
89+
SystemRuntimeCompilerServicesOverloadResolutionPriorityAttribute() {
90+
this.getNamespace() instanceof SystemRuntimeCompilerServicesNamespace and
91+
this.getType().hasName("OverloadResolutionPriorityAttribute")
92+
}
93+
94+
/**
95+
* Gets the priority number.
96+
*/
97+
int getPriority() { result = this.getConstructorArgument(0).getValue().toInt() }
98+
}

csharp/ql/test/library-tests/attributes/AttributeArguments.expected

Lines changed: 180 additions & 174 deletions
Large diffs are not rendered by default.
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
| attributes.cs:11:12:11:24 | [assembly: AssemblyTitle(...)] | attributes.cs:8:1:10:31 | // ... |
2-
| attributes.cs:23:12:23:21 | [assembly: ComVisible(...)] | attributes.cs:20:1:22:58 | // ... |
3-
| attributes.cs:26:12:26:15 | [assembly: Guid(...)] | attributes.cs:25:1:25:84 | // ... |
4-
| attributes.cs:38:12:38:26 | [assembly: AssemblyVersion(...)] | attributes.cs:28:1:37:39 | // ... |
1+
| attributes.cs:12:12:12:24 | [assembly: AssemblyTitle(...)] | attributes.cs:9:1:11:31 | // ... |
2+
| attributes.cs:24:12:24:21 | [assembly: ComVisible(...)] | attributes.cs:21:1:23:58 | // ... |
3+
| attributes.cs:27:12:27:15 | [assembly: Guid(...)] | attributes.cs:26:1:26:84 | // ... |
4+
| attributes.cs:39:12:39:26 | [assembly: AssemblyVersion(...)] | attributes.cs:29:1:38:39 | // ... |

csharp/ql/test/library-tests/attributes/AttributeElements.expected

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -9,48 +9,51 @@
99
| Assembly1.dll:0:0:0:0 | Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | Assembly1.dll:0:0:0:0 | [Debuggable(...)] | System.Diagnostics.DebuggableAttribute |
1010
| Assembly1.dll:0:0:0:0 | Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | Assembly1.dll:0:0:0:0 | [RuntimeCompatibility(...)] | System.Runtime.CompilerServices.RuntimeCompatibilityAttribute |
1111
| Assembly1.dll:0:0:0:0 | Assembly1, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | Assembly1.dll:0:0:0:0 | [TargetFramework(...)] | System.Runtime.Versioning.TargetFrameworkAttribute |
12-
| attributes.cs:45:7:45:9 | Foo | attributes.cs:44:2:44:22 | [AttributeUsage(...)] | System.AttributeUsageAttribute |
13-
| attributes.cs:48:17:48:19 | foo | attributes.cs:47:6:47:16 | [Conditional(...)] | System.Diagnostics.ConditionalAttribute |
14-
| attributes.cs:53:23:53:23 | x | attributes.cs:53:14:53:16 | [Foo(...)] | Foo |
15-
| attributes.cs:56:10:56:11 | M1 | attributes.cs:55:6:55:16 | [My(...)] | MyAttribute |
16-
| attributes.cs:60:10:60:11 | M2 | attributes.cs:58:6:58:16 | [My(...)] | MyAttribute |
17-
| attributes.cs:60:10:60:11 | M2 | attributes.cs:59:6:59:8 | [My2(...)] | My2Attribute |
18-
| attributes.cs:79:14:79:14 | X | attributes.cs:78:2:78:5 | [Args(...)] | ArgsAttribute |
19-
| attributes.cs:83:9:83:18 | SomeMethod | attributes.cs:81:6:81:9 | [Args(...)] | ArgsAttribute |
20-
| attributes.cs:83:9:83:18 | SomeMethod | attributes.cs:82:14:82:17 | [return: Args(...)] | ArgsAttribute |
21-
| attributes.cs:99:14:99:24 | Invoke | attributes.cs:98:10:98:21 | [return: My3(...)] | My3Attribute |
22-
| attributes.cs:99:14:99:24 | My1Delegate | attributes.cs:97:2:97:13 | [My3(...)] | My3Attribute |
23-
| attributes.cs:103:17:103:27 | Invoke | attributes.cs:101:10:101:21 | [return: My3(...)] | My3Attribute |
24-
| attributes.cs:103:17:103:27 | My2Delegate | attributes.cs:102:8:102:19 | [My3(...)] | My3Attribute |
25-
| attributes.cs:109:32:109:32 | + | attributes.cs:107:6:107:17 | [My3(...)] | My3Attribute |
26-
| attributes.cs:109:32:109:32 | + | attributes.cs:108:14:108:25 | [return: My3(...)] | My3Attribute |
27-
| attributes.cs:112:16:112:19 | Item | attributes.cs:111:6:111:17 | [My3(...)] | My3Attribute |
28-
| attributes.cs:116:9:116:11 | get_Item | attributes.cs:114:10:114:21 | [My3(...)] | My3Attribute |
29-
| attributes.cs:116:9:116:11 | get_Item | attributes.cs:115:18:115:29 | [return: My3(...)] | My3Attribute |
30-
| attributes.cs:120:9:120:11 | set_Item | attributes.cs:118:18:118:29 | [My3(...)] | My3Attribute |
31-
| attributes.cs:120:9:120:11 | value | attributes.cs:119:17:119:28 | [My3(...)] | My3Attribute |
32-
| attributes.cs:125:16:125:20 | Prop1 | attributes.cs:124:6:124:17 | [My3(...)] | My3Attribute |
33-
| attributes.cs:129:9:129:11 | get_Prop1 | attributes.cs:127:18:127:29 | [My3(...)] | My3Attribute |
34-
| attributes.cs:129:9:129:11 | get_Prop1 | attributes.cs:128:18:128:29 | [return: My3(...)] | My3Attribute |
35-
| attributes.cs:133:9:133:11 | set_Prop1 | attributes.cs:131:10:131:21 | [My3(...)] | My3Attribute |
36-
| attributes.cs:133:9:133:11 | value | attributes.cs:132:17:132:28 | [My3(...)] | My3Attribute |
37-
| attributes.cs:145:17:145:18 | M1 | attributes.cs:144:6:144:11 | [Params(...)] | Class1+ParamsAttribute |
38-
| attributes.cs:148:17:148:18 | M2 | attributes.cs:147:6:147:11 | [Params(...)] | Class1+ParamsAttribute |
39-
| attributes.cs:151:17:151:18 | M3 | attributes.cs:150:6:150:11 | [Params(...)] | Class1+ParamsAttribute |
40-
| attributes.cs:154:17:154:18 | M4 | attributes.cs:153:6:153:11 | [Params(...)] | Class1+ParamsAttribute |
41-
| attributes.cs:158:14:158:32 | MyExperimentalClass | attributes.cs:157:2:157:13 | [Experimental(...)] | System.Diagnostics.CodeAnalysis.ExperimentalAttribute |
42-
| attributes.cs:161:17:161:36 | MyExperimentalMethod | attributes.cs:160:6:160:17 | [Experimental(...)] | System.Diagnostics.CodeAnalysis.ExperimentalAttribute |
43-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:11:12:11:24 | [assembly: AssemblyTitle(...)] | System.Reflection.AssemblyTitleAttribute |
44-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:12:12:12:30 | [assembly: AssemblyDescription(...)] | System.Reflection.AssemblyDescriptionAttribute |
45-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:13:12:13:32 | [assembly: AssemblyConfiguration(...)] | System.Reflection.AssemblyConfigurationAttribute |
46-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:14:12:14:26 | [assembly: AssemblyCompany(...)] | System.Reflection.AssemblyCompanyAttribute |
47-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:15:12:15:26 | [assembly: AssemblyProduct(...)] | System.Reflection.AssemblyProductAttribute |
48-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:16:12:16:28 | [assembly: AssemblyCopyright(...)] | System.Reflection.AssemblyCopyrightAttribute |
49-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:17:12:17:28 | [assembly: AssemblyTrademark(...)] | System.Reflection.AssemblyTrademarkAttribute |
50-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:18:12:18:26 | [assembly: AssemblyCulture(...)] | System.Reflection.AssemblyCultureAttribute |
51-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:23:12:23:21 | [assembly: ComVisible(...)] | System.Runtime.InteropServices.ComVisibleAttribute |
52-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:26:12:26:15 | [assembly: Guid(...)] | System.Runtime.InteropServices.GuidAttribute |
53-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:38:12:38:26 | [assembly: AssemblyVersion(...)] | System.Reflection.AssemblyVersionAttribute |
54-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:39:12:39:30 | [assembly: AssemblyFileVersion(...)] | System.Reflection.AssemblyFileVersionAttribute |
55-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:41:12:41:15 | [assembly: Args(...)] | ArgsAttribute |
56-
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:42:10:42:13 | [module: Args(...)] | ArgsAttribute |
12+
| attributes.cs:46:7:46:9 | Foo | attributes.cs:45:2:45:22 | [AttributeUsage(...)] | System.AttributeUsageAttribute |
13+
| attributes.cs:49:17:49:19 | foo | attributes.cs:48:6:48:16 | [Conditional(...)] | System.Diagnostics.ConditionalAttribute |
14+
| attributes.cs:54:23:54:23 | x | attributes.cs:54:14:54:16 | [Foo(...)] | Foo |
15+
| attributes.cs:57:10:57:11 | M1 | attributes.cs:56:6:56:16 | [My(...)] | MyAttribute |
16+
| attributes.cs:61:10:61:11 | M2 | attributes.cs:59:6:59:16 | [My(...)] | MyAttribute |
17+
| attributes.cs:61:10:61:11 | M2 | attributes.cs:60:6:60:8 | [My2(...)] | My2Attribute |
18+
| attributes.cs:80:14:80:14 | X | attributes.cs:79:2:79:5 | [Args(...)] | ArgsAttribute |
19+
| attributes.cs:84:9:84:18 | SomeMethod | attributes.cs:82:6:82:9 | [Args(...)] | ArgsAttribute |
20+
| attributes.cs:84:9:84:18 | SomeMethod | attributes.cs:83:14:83:17 | [return: Args(...)] | ArgsAttribute |
21+
| attributes.cs:100:14:100:24 | Invoke | attributes.cs:99:10:99:21 | [return: My3(...)] | My3Attribute |
22+
| attributes.cs:100:14:100:24 | My1Delegate | attributes.cs:98:2:98:13 | [My3(...)] | My3Attribute |
23+
| attributes.cs:104:17:104:27 | Invoke | attributes.cs:102:10:102:21 | [return: My3(...)] | My3Attribute |
24+
| attributes.cs:104:17:104:27 | My2Delegate | attributes.cs:103:8:103:19 | [My3(...)] | My3Attribute |
25+
| attributes.cs:110:32:110:32 | + | attributes.cs:108:6:108:17 | [My3(...)] | My3Attribute |
26+
| attributes.cs:110:32:110:32 | + | attributes.cs:109:14:109:25 | [return: My3(...)] | My3Attribute |
27+
| attributes.cs:113:16:113:19 | Item | attributes.cs:112:6:112:17 | [My3(...)] | My3Attribute |
28+
| attributes.cs:117:9:117:11 | get_Item | attributes.cs:115:10:115:21 | [My3(...)] | My3Attribute |
29+
| attributes.cs:117:9:117:11 | get_Item | attributes.cs:116:18:116:29 | [return: My3(...)] | My3Attribute |
30+
| attributes.cs:121:9:121:11 | set_Item | attributes.cs:119:18:119:29 | [My3(...)] | My3Attribute |
31+
| attributes.cs:121:9:121:11 | value | attributes.cs:120:17:120:28 | [My3(...)] | My3Attribute |
32+
| attributes.cs:126:16:126:20 | Prop1 | attributes.cs:125:6:125:17 | [My3(...)] | My3Attribute |
33+
| attributes.cs:130:9:130:11 | get_Prop1 | attributes.cs:128:18:128:29 | [My3(...)] | My3Attribute |
34+
| attributes.cs:130:9:130:11 | get_Prop1 | attributes.cs:129:18:129:29 | [return: My3(...)] | My3Attribute |
35+
| attributes.cs:134:9:134:11 | set_Prop1 | attributes.cs:132:10:132:21 | [My3(...)] | My3Attribute |
36+
| attributes.cs:134:9:134:11 | value | attributes.cs:133:17:133:28 | [My3(...)] | My3Attribute |
37+
| attributes.cs:146:17:146:18 | M1 | attributes.cs:145:6:145:11 | [Params(...)] | Class1+ParamsAttribute |
38+
| attributes.cs:149:17:149:18 | M2 | attributes.cs:148:6:148:11 | [Params(...)] | Class1+ParamsAttribute |
39+
| attributes.cs:152:17:152:18 | M3 | attributes.cs:151:6:151:11 | [Params(...)] | Class1+ParamsAttribute |
40+
| attributes.cs:155:17:155:18 | M4 | attributes.cs:154:6:154:11 | [Params(...)] | Class1+ParamsAttribute |
41+
| attributes.cs:159:14:159:32 | MyExperimentalClass | attributes.cs:158:2:158:13 | [Experimental(...)] | System.Diagnostics.CodeAnalysis.ExperimentalAttribute |
42+
| attributes.cs:162:17:162:36 | MyExperimentalMethod | attributes.cs:161:6:161:17 | [Experimental(...)] | System.Diagnostics.CodeAnalysis.ExperimentalAttribute |
43+
| attributes.cs:168:17:168:17 | M | attributes.cs:167:6:167:31 | [OverloadResolutionPriority(...)] | System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute |
44+
| attributes.cs:171:17:171:17 | M | attributes.cs:170:6:170:31 | [OverloadResolutionPriority(...)] | System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute |
45+
| attributes.cs:174:17:174:17 | M | attributes.cs:173:6:173:31 | [OverloadResolutionPriority(...)] | System.Runtime.CompilerServices.OverloadResolutionPriorityAttribute |
46+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:12:12:12:24 | [assembly: AssemblyTitle(...)] | System.Reflection.AssemblyTitleAttribute |
47+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:13:12:13:30 | [assembly: AssemblyDescription(...)] | System.Reflection.AssemblyDescriptionAttribute |
48+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:14:12:14:32 | [assembly: AssemblyConfiguration(...)] | System.Reflection.AssemblyConfigurationAttribute |
49+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:15:12:15:26 | [assembly: AssemblyCompany(...)] | System.Reflection.AssemblyCompanyAttribute |
50+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:16:12:16:26 | [assembly: AssemblyProduct(...)] | System.Reflection.AssemblyProductAttribute |
51+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:17:12:17:28 | [assembly: AssemblyCopyright(...)] | System.Reflection.AssemblyCopyrightAttribute |
52+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:18:12:18:28 | [assembly: AssemblyTrademark(...)] | System.Reflection.AssemblyTrademarkAttribute |
53+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:19:12:19:26 | [assembly: AssemblyCulture(...)] | System.Reflection.AssemblyCultureAttribute |
54+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:24:12:24:21 | [assembly: ComVisible(...)] | System.Runtime.InteropServices.ComVisibleAttribute |
55+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:27:12:27:15 | [assembly: Guid(...)] | System.Runtime.InteropServices.GuidAttribute |
56+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:39:12:39:26 | [assembly: AssemblyVersion(...)] | System.Reflection.AssemblyVersionAttribute |
57+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:40:12:40:30 | [assembly: AssemblyFileVersion(...)] | System.Reflection.AssemblyFileVersionAttribute |
58+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:42:12:42:15 | [assembly: Args(...)] | ArgsAttribute |
59+
| attributes.dll:0:0:0:0 | attributes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null | attributes.cs:43:10:43:13 | [module: Args(...)] | ArgsAttribute |
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| attributes.cs:158:14:158:32 | MyExperimentalClass | attributes.cs:157:2:157:13 | [Experimental(...)] | MyExperimentalClassId |
2-
| attributes.cs:161:17:161:36 | MyExperimentalMethod | attributes.cs:160:6:160:17 | [Experimental(...)] | MyExperimentalMethodId |
1+
| attributes.cs:159:14:159:32 | MyExperimentalClass | attributes.cs:158:2:158:13 | [Experimental(...)] | MyExperimentalClassId |
2+
| attributes.cs:162:17:162:36 | MyExperimentalMethod | attributes.cs:161:6:161:17 | [Experimental(...)] | MyExperimentalMethodId |
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
| attributes.cs:168:17:168:17 | M | attributes.cs:167:6:167:31 | [OverloadResolutionPriority(...)] | -1 |
2+
| attributes.cs:171:17:171:17 | M | attributes.cs:170:6:170:31 | [OverloadResolutionPriority(...)] | 1 |
3+
| attributes.cs:174:17:174:17 | M | attributes.cs:173:6:173:31 | [OverloadResolutionPriority(...)] | 2 |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import csharp
2+
import semmle.code.csharp.frameworks.system.runtime.CompilerServices
3+
4+
from
5+
Attributable element, SystemRuntimeCompilerServicesOverloadResolutionPriorityAttribute attribute
6+
where attribute = element.getAnAttribute() and attribute.fromSource()
7+
select element, attribute, attribute.getPriority()

0 commit comments

Comments
 (0)