Skip to content

Commit 914da6b

Browse files
committed
Fix various stubbing issues
1 parent fec0ddd commit 914da6b

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,11 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
7171
}
7272

7373
private string stubPartialModifier() {
74-
if count(Assembly a | this.getALocation() = a) > 1 then result = "partial " else result = ""
74+
if
75+
count(Assembly a | this.getALocation() = a) <= 1 or
76+
this instanceof Enum
77+
then result = ""
78+
else result = "partial "
7579
}
7680

7781
private string stubAttributes() {
@@ -100,9 +104,10 @@ abstract private class GeneratedType extends ValueOrRefType, GeneratedElement {
100104
stubMembers(assembly) + "}\n\n"
101105
or
102106
result =
103-
this.stubComment() + this.stubAttributes() + stubAccessibility(this) + this.stubKeyword() +
104-
" " + stubClassName(this.(DelegateType).getReturnType()) + " " + this.getUndecoratedName()
105-
+ stubGenericArguments(this) + "(" + stubParameters(this) + ");\n\n"
107+
this.stubComment() + this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) +
108+
this.stubKeyword() + " " + stubClassName(this.(DelegateType).getReturnType()) + " " +
109+
this.getUndecoratedName() + stubGenericArguments(this) + "(" + stubParameters(this) +
110+
");\n\n"
106111
)
107112
}
108113

@@ -669,6 +674,12 @@ private string stubDefaultValue(Parameter p) {
669674
else result = ""
670675
}
671676

677+
private string stubEventAccessors(Event e) {
678+
if exists(e.(Virtualizable).getExplicitlyImplementedInterface())
679+
then result = " { add => throw null; remove => throw null; }"
680+
else result = ";"
681+
}
682+
672683
private string stubExplicitImplementation(Member c) {
673684
if exists(c.(Virtualizable).getExplicitlyImplementedInterface())
674685
then result = stubClassName(c.(Virtualizable).getExplicitlyImplementedInterface()) + "."
@@ -748,7 +759,8 @@ private string stubMember(Member m, Assembly assembly) {
748759
then
749760
result =
750761
" " + stubModifiers(m) + "event " + stubClassName(m.(Event).getType()) +
751-
" " + stubExplicitImplementation(m) + m.getName() + ";\n"
762+
" " + stubExplicitImplementation(m) + m.getName() + stubEventAccessors(m) +
763+
"\n"
752764
else
753765
if m instanceof GeneratedType
754766
then result = m.(GeneratedType).getStub(assembly) + "\n"

0 commit comments

Comments
 (0)