Skip to content

Commit 97cd006

Browse files
committed
Add missing required private constructors
1 parent d7a93a5 commit 97cd006

File tree

1 file changed

+28
-15
lines changed

1 file changed

+28
-15
lines changed

csharp/ql/src/Stubs/Stubs.qll

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ abstract private class GeneratedType extends Type, GeneratedElement {
138138
this.stubComment() + this.stubAttributes() + stubAccessibility(this) +
139139
this.stubAbstractModifier() + this.stubStaticModifier() + this.stubPartialModifier() +
140140
this.stubKeyword() + " " + this.getUndecoratedName() + stubGenericArguments(this) +
141-
stubBaseTypesString() + stubTypeParametersConstraints(this) + "\n{\n" +
142-
stubMembers(assembly) + "}\n\n"
141+
this.stubBaseTypesString() + stubTypeParametersConstraints(this) + "\n{\n" +
142+
this.stubPrivateConstructor() + this.stubMembers(assembly) + "}\n\n"
143143
or
144144
result =
145145
this.stubComment() + this.stubAttributes() + stubUnsafe(this) + stubAccessibility(this) +
@@ -183,6 +183,22 @@ abstract private class GeneratedType extends Type, GeneratedElement {
183183
)
184184
}
185185

186+
string stubPrivateConstructor() {
187+
if
188+
this instanceof Interface or
189+
this.isStatic() or
190+
this.isAbstract() or
191+
exists(this.(ValueOrRefType).getAConstructor()) or
192+
not exists(this.getAnInterestingBaseType()) or
193+
not exists(this.getAnInterestingBaseType().getAConstructor()) or
194+
this.getAnInterestingBaseType().getAConstructor().getNumberOfParameters() = 0
195+
then result = ""
196+
else
197+
result =
198+
" private " + this.getUndecoratedName() + "() : base(" +
199+
stubDefaultArguments(getBaseConstructor(this), this) + ")" + " => throw null;\n"
200+
}
201+
186202
private GeneratedMember getAGeneratedMember() { result.getDeclaringType() = this }
187203

188204
final Type getAGeneratedType() {
@@ -670,18 +686,15 @@ private string stubParameters(Parameterizable p) {
670686
)
671687
}
672688

673-
private string stubDefaultArguments(Constructor baseCtor) {
674-
exists(Constructor c |
675-
baseCtor = getBaseConstructor(c.getDeclaringType()) and
676-
baseCtor.getNumberOfParameters() > 0 and
677-
not c.isStatic() and
678-
result =
679-
concat(int i, Parameter param |
680-
param = baseCtor.getParameter(i) and not param.getType() instanceof ArglistType
681-
|
682-
"default(" + stubClassName(param.getType()) + ")", ", " order by i
683-
)
684-
)
689+
private string stubDefaultArguments(Constructor baseCtor, ValueOrRefType callingType) {
690+
baseCtor = getBaseConstructor(callingType) and
691+
baseCtor.getNumberOfParameters() > 0 and
692+
result =
693+
concat(int i, Parameter param |
694+
param = baseCtor.getParameter(i) and not param.getType() instanceof ArglistType
695+
|
696+
"default(" + stubClassName(param.getType()) + ")", ", " order by i
697+
)
685698
}
686699

687700
private string stubParameterModifiers(Parameter p) {
@@ -827,7 +840,7 @@ private string stubConstructorInitializer(Constructor c) {
827840
baseCtor = getBaseConstructor(c.getDeclaringType()) and
828841
if baseCtor.getNumberOfParameters() = 0 or c.isStatic()
829842
then result = ""
830-
else result = " : base(" + stubDefaultArguments(baseCtor) + ")"
843+
else result = " : base(" + stubDefaultArguments(baseCtor, c.getDeclaringType()) + ")"
831844
)
832845
or
833846
// abstract base class might not have a constructor

0 commit comments

Comments
 (0)