Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,10 @@ dependencies {

testImplementation project(':groovy-ant')
testImplementation project(':groovy-xml')
testImplementation project(':groovy-dateutil')
testImplementation project(':groovy-json')
testImplementation project(':groovy-test')
testImplementation project(':groovy-macro')
testImplementation project(':groovy-dateutil')
}

ext.generatedDirectory = "${buildDir}/generated/sources"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@
import static org.codehaus.groovy.syntax.Types.KEYWORD_IN;
import static org.codehaus.groovy.syntax.Types.KEYWORD_INSTANCEOF;
import static org.codehaus.groovy.syntax.Types.LEFT_SQUARE_BRACKET;
import static org.codehaus.groovy.syntax.Types.LOGICAL_OR;
import static org.codehaus.groovy.syntax.Types.MINUS_MINUS;
import static org.codehaus.groovy.syntax.Types.MOD;
import static org.codehaus.groovy.syntax.Types.MOD_EQUAL;
Expand Down Expand Up @@ -727,6 +728,9 @@ public void visitBinaryExpression(final BinaryExpression expression) {
typeCheckingContext.pushEnclosingBinaryExpression(expression);
try {
int op = expression.getOperation().getType();
if (op == LOGICAL_OR) {
typeCheckingContext.pushTemporaryTypeInfo();
}
Expression leftExpression = expression.getLeftExpression();
Expression rightExpression = expression.getRightExpression();

Expand All @@ -735,6 +739,7 @@ public void visitBinaryExpression(final BinaryExpression expression) {
ClassNode lType = null;
if (setterInfo != null) {
if (ensureValidSetter(expression, leftExpression, rightExpression, setterInfo)) {
if (op == LOGICAL_OR) typeCheckingContext.popTemporaryTypeInfo();
return;
}
} else {
Expand Down Expand Up @@ -780,6 +785,8 @@ public void visitBinaryExpression(final BinaryExpression expression) {
elvisOperatorExpression.visit(this);
resultType = getType(elvisOperatorExpression);
storeType(leftExpression, resultType);
} else if (op == LOGICAL_OR) {
typeCheckingContext.popTemporaryTypeInfo();
}

if (resultType == null) {
Expand Down
23 changes: 21 additions & 2 deletions src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
foo(it)
}
}
''', 'Reference to method is ambiguous'
''', 'Cannot find matching method'
}

void testShouldFailWithMultiplePossibleMethods2() {
Expand All @@ -420,7 +420,26 @@ class MethodCallsSTCTest extends StaticTypeCheckingTestCase {
foo(argument)
}
}
''', 'Reference to method is ambiguous'
''', 'Cannot find matching method'
}

// GROOVY-7971
void testShouldNotFailWithMultiplePossibleMethods() {
assertScript '''
import groovy.json.JsonOutput

def test(value) {
def out = new StringBuilder()
def isString = value.class == String
if (isString || value instanceof Map) {
out.append(JsonOutput.toJson(value))
}
return out.toString()
}

def string = test('two')
assert string == '"two"'
'''
}

void testInstanceOfOnExplicitParameter() {
Expand Down