Basic lookup for unqualified function calls
This commit is contained in:
@@ -54,4 +54,8 @@ public class JetChangeUtil {
|
||||
public static PsiElement createNameIdentifier(Project project, String name) {
|
||||
return createProperty(project, name, null).getNameIdentifier();
|
||||
}
|
||||
|
||||
public static JetFunction createFunction(Project project, String funDecl) {
|
||||
return createDeclaration(project, funDecl, JetFunction.class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,7 +84,8 @@ public class ClassDescriptorResolver {
|
||||
return memberDeclarations;
|
||||
}
|
||||
|
||||
private FunctionDescriptor resolveFunctionDescriptor(JetScope scope, JetFunction function) {
|
||||
@NotNull
|
||||
public FunctionDescriptor resolveFunctionDescriptor(JetScope scope, JetFunction function) {
|
||||
ParameterExtensibleScope parameterScope = new ParameterExtensibleScope(scope);
|
||||
// The two calls below have side-effects on parameterScope
|
||||
List<TypeParameterDescriptor> typeParameterDescriptors = resolveTypeParameters(parameterScope, function.getTypeParameters());
|
||||
|
||||
@@ -367,7 +367,7 @@ public class JetTypeChecker {
|
||||
@Override
|
||||
public void visitReferenceExpression(JetReferenceExpression expression) {
|
||||
// a -- create a hierarchical lookup domain for this.a
|
||||
throw new UnsupportedOperationException(); // TODO
|
||||
result[0] = OverloadResolver.INSTANCE.getOverloadDomain(null, scope, expression.getReferencedName());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -323,6 +323,14 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
assertType("new Functions<String>().f(1d)", (String) null);
|
||||
assertType("new Functions<Double>().f(())", "Double");
|
||||
assertType("new Functions<Double>().f(1d)", "Any");
|
||||
assertType("new Functions<Byte>().f<String>(\"\")", "Byte");
|
||||
assertType("new Functions<Byte>().f<String>(1)", (String) null);
|
||||
|
||||
assertType("f()", "Unit");
|
||||
assertType("f(1)", "Int");
|
||||
assertType("f(1f, 1)", "Float");
|
||||
assertType("f<String>(1f)", "String");
|
||||
assertType("f(1.0)", (String) null);
|
||||
}
|
||||
|
||||
// public void testImplicitConversions() throws Exception {
|
||||
@@ -434,8 +442,15 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
"fun f(a : Int) : Int {} " +
|
||||
"fun f(a : T) : Any {} " +
|
||||
"fun f(a : Unit) : T {} " +
|
||||
"fun f<E>(a : E) : T {} " +
|
||||
"}"
|
||||
};
|
||||
private static String[] FUNCTION_DECLARATIONS = {
|
||||
"fun f() : Unit {}",
|
||||
"fun f(a : Int) : Int {a}",
|
||||
"fun f(a : Float, b : Int) : Float {a}",
|
||||
"fun f<T>(a : Float) : T {a}",
|
||||
};
|
||||
|
||||
public static JetScope BASIC_SCOPE = new JetScopeAdapter(JetStandardClasses.STANDARD_CLASSES) {
|
||||
@Override
|
||||
@@ -453,6 +468,19 @@ public class JetTypeCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
}
|
||||
return super.getClass(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public FunctionGroup getFunctionGroup(@NotNull String name) {
|
||||
WritableFunctionGroup writableFunctionGroup = new WritableFunctionGroup(name);
|
||||
for (String funDecl : FUNCTION_DECLARATIONS) {
|
||||
FunctionDescriptor functionDescriptor = ClassDescriptorResolver.INSTANCE.resolveFunctionDescriptor(this, JetChangeUtil.createFunction(getProject(), funDecl));
|
||||
if (name.equals(functionDescriptor.getName())) {
|
||||
writableFunctionGroup.addFunction(functionDescriptor);
|
||||
}
|
||||
}
|
||||
return writableFunctionGroup;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user