KT-11100 Fix generation of name of FakeCallableDescriptorForObject that is presumably used to express invoke operator on (companion) objects
This commit is contained in:
@@ -59,4 +59,8 @@ public final class ClassObjectTest extends SingleFileTranslationTest {
|
||||
public void testObjectInCompanionObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
|
||||
public void testInvokeOperatorInCompanionObject() throws Exception {
|
||||
checkFooBoxIsOk();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.jetbrains.kotlin.name.FqName;
|
||||
import org.jetbrains.kotlin.resolve.BindingContext;
|
||||
import org.jetbrains.kotlin.resolve.BindingTrace;
|
||||
import org.jetbrains.kotlin.resolve.DescriptorUtils;
|
||||
import org.jetbrains.kotlin.resolve.calls.util.FakeCallableDescriptorForObject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -383,6 +384,19 @@ public final class StaticContext {
|
||||
}
|
||||
};
|
||||
|
||||
Rule<JsName> fakeCallableDescriptor = new Rule<JsName>() {
|
||||
@Nullable
|
||||
@Override
|
||||
public JsName apply(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (!(descriptor instanceof FakeCallableDescriptorForObject)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FakeCallableDescriptorForObject fakeCallableDescriptor = (FakeCallableDescriptorForObject) descriptor;
|
||||
return getNameForDescriptor(fakeCallableDescriptor.getReferencedDescriptor());
|
||||
}
|
||||
};
|
||||
|
||||
addRule(namesForDynamic);
|
||||
addRule(localClasses);
|
||||
addRule(namesForStandardClasses);
|
||||
@@ -390,6 +404,7 @@ public final class StaticContext {
|
||||
addRule(propertyOrPropertyAccessor);
|
||||
addRule(predefinedObjectsHasUnobfuscatableNames);
|
||||
addRule(overridingDescriptorsReferToOriginalName);
|
||||
addRule(fakeCallableDescriptor);
|
||||
addRule(memberDeclarationsInsideParentsScope);
|
||||
}
|
||||
}
|
||||
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
// See KT-11100
|
||||
package foo
|
||||
|
||||
class Div {
|
||||
var className: String? = null
|
||||
|
||||
companion object {
|
||||
operator fun invoke(init: Div.() -> Unit): Div {
|
||||
val div = Div()
|
||||
div.init()
|
||||
return div
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
val x = Div {
|
||||
className = "ui container"
|
||||
}
|
||||
assertEquals("ui container", x.className)
|
||||
return "OK"
|
||||
}
|
||||
Reference in New Issue
Block a user