mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-57101 Groovy array member access is untyped
This commit is contained in:
+7
-7
@@ -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) {}
|
||||
Reference in New Issue
Block a user