map String methods; don't try to push void values on stack

This commit is contained in:
Dmitry Jemerov
2011-05-26 19:32:39 +04:00
parent 58f50a8046
commit 2a0567d15b
2 changed files with 27 additions and 1 deletions
@@ -682,7 +682,24 @@ public class ExpressionCodegen extends JetVisitor {
}
}
PsiElement declarationPsiElement = bindingContext.getDeclarationPsiElement(funDescriptor);
if (declarationPsiElement == null && isClass(functionParent, "String")) {
final Project project = expression.getProject();
PsiClass jlString = JavaPsiFacade.getInstance(project).findClass("java.lang.String",
ProjectScope.getAllScope(project));
// TODO better overload mapping
final PsiMethod[] methods = jlString.findMethodsByName(funDescriptor.getName(), false);
final int arity = ((FunctionDescriptor) funDescriptor).getUnsubstitutedValueParameters().size();
for (PsiMethod method : methods) {
if (method.getParameterList().getParametersCount() == arity) {
declarationPsiElement = method;
}
}
}
if (declarationPsiElement == null) {
throw new UnsupportedOperationException("couldn't find declaration for " + funDescriptor);
}
Method methodDescriptor;
if (declarationPsiElement instanceof PsiMethod) {
PsiMethod psiMethod = (PsiMethod) declarationPsiElement;
@@ -1629,7 +1646,10 @@ public class ExpressionCodegen extends JetVisitor {
v.athrow();
}
v.mark(end);
myStack.push(StackValue.onStack(expressionType(expression)));
final Type type = expressionType(expression);
if (type.getSort() != Type.VOID) {
myStack.push(StackValue.onStack(type));
}
myMap.leaveTemp(subjectType.getSize());
}
@@ -55,4 +55,10 @@ public class PatternMatchingTest extends CodegenTestCase {
Method foo = generateFunction();
assertEquals("something", foo.invoke(null, ""));
}
public void testNoReturnType() throws Exception {
loadText("fun foo(x: String) = when(x) { is * => return \"x\" }");
Method foo = generateFunction();
assertEquals("x", foo.invoke(null, ""));
}
}