Support property accessor in inline checks
This commit is contained in:
+2
-2
@@ -50,12 +50,12 @@ import static org.jetbrains.kotlin.resolve.inline.InlineUtil.allowsNonLocalRetur
|
||||
import static org.jetbrains.kotlin.resolve.inline.InlineUtil.checkNonLocalReturnUsage;
|
||||
|
||||
class InlineChecker implements SimpleCallChecker {
|
||||
private final SimpleFunctionDescriptor descriptor;
|
||||
private final FunctionDescriptor descriptor;
|
||||
private final Set<CallableDescriptor> inlinableParameters = new LinkedHashSet<CallableDescriptor>();
|
||||
private final boolean isEffectivelyPublicApiFunction;
|
||||
private final boolean isEffectivelyPrivateApiFunction;
|
||||
|
||||
public InlineChecker(@NotNull SimpleFunctionDescriptor descriptor) {
|
||||
public InlineChecker(@NotNull FunctionDescriptor descriptor) {
|
||||
assert InlineUtil.isInline(descriptor) : "This extension should be created only for inline functions: " + descriptor;
|
||||
this.descriptor = descriptor;
|
||||
this.isEffectivelyPublicApiFunction = DescriptorUtilsKt.isEffectivelyPublicApi(descriptor);
|
||||
|
||||
+3
-3
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.resolve.calls.checkers
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor
|
||||
import org.jetbrains.kotlin.descriptors.FunctionDescriptor
|
||||
import org.jetbrains.kotlin.resolve.calls.context.BasicCallResolutionContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.inline.InlineUtil
|
||||
@@ -33,7 +33,7 @@ class InlineCheckerWrapper : SimpleCallChecker {
|
||||
|
||||
while (parentDescriptor != null) {
|
||||
if (InlineUtil.isInline(parentDescriptor)) {
|
||||
val checker = getChecker(parentDescriptor as SimpleFunctionDescriptor)
|
||||
val checker = getChecker(parentDescriptor as FunctionDescriptor)
|
||||
checker.check(resolvedCall, context)
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class InlineCheckerWrapper : SimpleCallChecker {
|
||||
}
|
||||
}
|
||||
|
||||
private fun getChecker(descriptor: SimpleFunctionDescriptor): SimpleCallChecker {
|
||||
private fun getChecker(descriptor: FunctionDescriptor): SimpleCallChecker {
|
||||
val map = checkersCache?.get() ?: hashMapOf()
|
||||
checkersCache = checkersCache ?: WeakReference(map)
|
||||
return map.getOrPut(descriptor) { InlineChecker(descriptor) }
|
||||
|
||||
@@ -40,7 +40,7 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
public static boolean isInline(@Nullable DeclarationDescriptor descriptor) {
|
||||
return descriptor instanceof SimpleFunctionDescriptor && getInlineStrategy(descriptor).isInline();
|
||||
return descriptor instanceof FunctionDescriptor && getInlineStrategy((FunctionDescriptor) descriptor).isInline();
|
||||
}
|
||||
|
||||
public static boolean isInlineOrContainingInline(@Nullable DeclarationDescriptor descriptor) {
|
||||
@@ -50,9 +50,8 @@ public class InlineUtil {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static InlineStrategy getInlineStrategy(@NotNull DeclarationDescriptor descriptor) {
|
||||
if (descriptor instanceof FunctionDescriptor &&
|
||||
((FunctionDescriptor) descriptor).isInline()) {
|
||||
private static InlineStrategy getInlineStrategy(@NotNull FunctionDescriptor descriptor) {
|
||||
if (descriptor.isInline()) {
|
||||
return InlineStrategy.AS_FUNCTION;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
// !DIAGNOSTICS: -UNUSED_VARIABLE -INFIX_MODIFIER_REQUIRED
|
||||
|
||||
inline var value: (p: Int) -> String
|
||||
get() = {"123" }
|
||||
set(s: (p: Int) -> String) {
|
||||
s(11)
|
||||
s.invoke(11)
|
||||
s invoke 11
|
||||
|
||||
val z = <!USAGE_IS_NOT_INLINABLE!>s<!>
|
||||
}
|
||||
|
||||
inline var value2: Int.(p: Int) -> String
|
||||
get() = {"123" }
|
||||
set(ext: Int.(p: Int) -> String) {
|
||||
11.ext(11)
|
||||
11.ext(11)
|
||||
|
||||
val p = <!USAGE_IS_NOT_INLINABLE!>ext<!>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public var value: (kotlin.Int) -> kotlin.String
|
||||
public var value2: kotlin.Int.(kotlin.Int) -> kotlin.String
|
||||
@@ -10146,6 +10146,21 @@ public class DiagnosticsTestGenerated extends AbstractDiagnosticsTest {
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inline/property")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
public static class Property extends AbstractDiagnosticsTest {
|
||||
public void testAllFilesPresentInProperty() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/inline/property"), Pattern.compile("^(.+)\\.kt$"), true);
|
||||
}
|
||||
|
||||
@TestMetadata("invoke.kt")
|
||||
public void testInvoke() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/inline/property/invoke.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/diagnostics/tests/inline/regressions")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user