String is assignable to char

This commit is contained in:
Maxim Medvedev
2011-04-19 14:54:23 +04:00
parent d7285d13f9
commit 30d04a30f2
5 changed files with 23 additions and 7 deletions
@@ -29,6 +29,8 @@ public interface GrClosureSignature {
@NotNull
GrClosureParameter[] getParameters();
int getParameterCount();
boolean isVarargs();
@Nullable
@@ -36,7 +36,6 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement;
import org.jetbrains.plugins.groovy.lang.psi.api.GroovyResolveResult;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrBinaryExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureParameter;
import org.jetbrains.plugins.groovy.lang.psi.api.types.GrClosureSignature;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrTupleType;
@@ -50,6 +49,7 @@ import java.util.Map;
import static com.intellij.psi.CommonClassNames.*;
import static org.jetbrains.plugins.groovy.lang.lexer.GroovyTokenTypes.*;
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.GROOVY_LANG_GSTRING;
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.JAVA_MATH_BIG_DECIMAL;
import static org.jetbrains.plugins.groovy.lang.psi.util.GroovyCommonClassNames.JAVA_MATH_BIG_INTEGER;
@@ -304,6 +304,11 @@ public class TypesUtil {
lType = boxPrimitiveType(lType, manager, scope);
}
if (unboxPrimitiveTypeWrapper(lType) == PsiType.CHAR &&
(typeEqualsToText(rType, GROOVY_LANG_GSTRING) || typeEqualsToText(rType, JAVA_LANG_STRING))) {
return true;
}
return TypeConversionUtil.isAssignable(lType, rType);
}
@@ -393,13 +398,10 @@ public class TypesUtil {
else if (type1 instanceof GrClosureType && type2 instanceof GrClosureType) {
GrClosureType clType1 = (GrClosureType)type1;
GrClosureType clType2 = (GrClosureType)type2;
GrClosureSignature signature1=clType1.getSignature();
GrClosureSignature signature2=clType2.getSignature();
GrClosureSignature signature1 = clType1.getSignature();
GrClosureSignature signature2 = clType2.getSignature();
GrClosureParameter[] parameters1 = signature1.getParameters();
GrClosureParameter[] parameters2 = signature2.getParameters();
if (parameters1.length == parameters2.length) {
if (signature1.getParameterCount() == signature2.getParameterCount()) {
final GrClosureSignature signature = GrClosureSignatureImpl.getLeastUpperBound(signature1, signature2, manager);
if (signature != null) {
GlobalSearchScope scope = clType1.getResolveScope().intersectWith(clType2.getResolveScope());
@@ -82,6 +82,11 @@ public class GrClosureSignatureImpl implements GrClosureSignature {
return result;
}
@Override
public int getParameterCount() {
return myParameters.length;
}
@Nullable
public GrClosureSignature curry(int count) {
if (count > myParameters.length) {
@@ -375,4 +375,8 @@ public class GroovyHighlightingTest extends LightCodeInsightFixtureTestCase {
doTest(new UnusedDefInspection());
}
public void testStringAssignableToChar() {
doTest(new GroovyAssignabilityCheckInspection());
}
}
@@ -0,0 +1,3 @@
def a='string text'
char ch = a //here should not be inspection warning
int x = <warning descr="Cannot assign 'String' to 'int'">a</warning> //check that assignability inspection is on.