IDEA-57101 Groovy array member access is untyped

This commit is contained in:
Maxim Medvedev
2010-08-04 11:22:02 +04:00
parent 11963c41c8
commit 2ca2154a8a
3 changed files with 22 additions and 7 deletions
@@ -75,7 +75,12 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp
argTypes[i] = argType;
}
if (thisType instanceof GrTupleType &&
if (thisType instanceof PsiArrayType &&
argTypes.length == 1 &&
TypesUtil.isAssignable(PsiType.INT, argTypes[0], getManager(), getResolveScope())) {
return TypesUtil.boxPrimitiveType(((PsiArrayType)thisType).getComponentType(), getManager(), getResolveScope());
}
else if (thisType instanceof GrTupleType &&
argTypes.length == 1 &&
TypesUtil.isAssignable(PsiType.INT, argTypes[0], getManager(), getResolveScope())) {
PsiType[] types = ((GrTupleType)thisType).getParameters();
@@ -96,12 +101,7 @@ public class GrIndexPropertyImpl extends GrExpressionImpl implements GrIndexProp
}
PsiType componentType = null;
if (thisType instanceof PsiArrayType &&
argTypes.length == 1 &&
TypesUtil.isAssignable(PsiType.INT, argTypes[0], getManager(), getResolveScope())) {
componentType = TypesUtil.boxPrimitiveType(((PsiArrayType)thisType).getComponentType(), getManager(), getResolveScope());
}
else if (InheritanceUtil.isInheritor(thisType, CommonClassNames.JAVA_UTIL_MAP) && argTypes.length == 1) {
if (InheritanceUtil.isInheritor(thisType, CommonClassNames.JAVA_UTIL_MAP) && argTypes.length == 1) {
componentType = TypesUtil
.boxPrimitiveType(substituteTypeParameter(thisType, CommonClassNames.JAVA_UTIL_MAP, 1, true), getManager(), getResolveScope());
}
@@ -15,11 +15,14 @@
*/
package org.jetbrains.plugins.groovy.lang.resolve;
import com.intellij.psi.CommonClassNames;
import com.intellij.psi.PsiIntersectionType;
import com.intellij.psi.PsiReference;
import com.intellij.psi.PsiType;
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrReferenceExpression;
import org.jetbrains.plugins.groovy.lang.psi.impl.GrClosureType;
import org.jetbrains.plugins.groovy.util.TestUtils;
import org.jmock.lib.CamelCaseNamingScheme;
/**
* @author ven
@@ -122,4 +125,9 @@ public class TypeInferenceTest extends GroovyResolveTestCase {
final GrReferenceExpression ref = (GrReferenceExpression)configureByFile("arrayLikeAccessWithIntSequence/A.groovy").getElement();
assertEquals("java.util.List", ref.getType().getCanonicalText());
}
public void testArrayAccess() {
final GrReferenceExpression ref = (GrReferenceExpression)configureByFile("arrayAccess/A.groovy");
assertEquals(CommonClassNames.JAVA_LANG_STRING, ref.getType().getCanonicalText());
}
}
@@ -0,0 +1,7 @@
def foo(String[] a) {
def var = a[0]
print va<ref>r
}
def bar(String a) {}