You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// "this" in mutates means the callee mutates its receiver
269
+
if (contractMutates.contains('this')) {
270
+
addStaticTypeError("@Modifies warning: call to 'this.${call.methodAsString}()' declares @Contract(mutates=\"this\") — may modify fields not in @Modifies", call)
addStaticTypeError("@Modifies warning: call to '${receiverName}.${call.methodAsString}()' may modify '${receiverName}' which is not in @Modifies", call)
314
+
}
315
+
return
316
+
}
317
+
}
221
318
222
319
// Known-safe method name
223
320
if (SAFE_METHOD_NAMES.contains(call.methodAsString)) return
@@ -228,6 +325,51 @@ class ModifiesChecker extends GroovyTypeCheckingExtensionSupport.TypeCheckingDSL
if (contractMutates !=null&&!contractMutates.isEmpty()) {
335
+
// Static methods can't mutate "this", but can mutate params
336
+
def args = call.arguments
337
+
if (args instanceoforg.codehaus.groovy.ast.expr.TupleExpression) {
338
+
def argList = args.expressions
339
+
def params = targetMethod.parameters
340
+
for (int i =0; i < params.length && i < argList.size(); i++) {
341
+
if (contractMutates.contains(params[i].name)) {
342
+
String argName = resolveReceiverName(argList[i])
343
+
if (argName &&!modifiesSet.contains(argName)) {
344
+
addStaticTypeError("@Modifies warning: argument '${argName}' passed to '${call.methodAsString}()' parameter '${params[i].name}' which is declared as mutated", call)
345
+
}
346
+
}
347
+
}
348
+
}
349
+
}
350
+
}
351
+
352
+
/**
353
+
* For @Contract(mutates="param1,param2"), check if the actual arguments
354
+
* at the call site are variables not in our modifies set.
if (!(args instanceoforg.codehaus.groovy.ast.expr.TupleExpression)) return
359
+
def argList = args.expressions
360
+
def params = callee.parameters
361
+
362
+
for (int i =0; i < params.length && i < argList.size(); i++) {
363
+
if (contractMutates.contains(params[i].name)) {
364
+
// This parameter is mutated — check what argument was passed
365
+
String argName = resolveReceiverName(argList[i])
366
+
if (argName &&!modifiesSet.contains(argName)) {
367
+
addStaticTypeError("@Modifies warning: argument '${argName}' passed to '${call.methodAsString}()' parameter '${params[i].name}' which is declared as mutated", call)
0 commit comments