JvmSynthetic forbidden for delegated properties (and searched for different use-site targets)
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2016 JetBrains s.r.o.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.resolve.jvm.checkers
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.descriptors.DeclarationDescriptor
|
||||||
|
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||||
|
import org.jetbrains.kotlin.psi.KtDeclaration
|
||||||
|
import org.jetbrains.kotlin.psi.KtProperty
|
||||||
|
import org.jetbrains.kotlin.resolve.BindingContext
|
||||||
|
import org.jetbrains.kotlin.resolve.DeclarationChecker
|
||||||
|
import org.jetbrains.kotlin.resolve.DescriptorToSourceUtils
|
||||||
|
import org.jetbrains.kotlin.resolve.annotations.findJvmSyntheticAnnotation
|
||||||
|
import org.jetbrains.kotlin.resolve.jvm.diagnostics.ErrorsJvm
|
||||||
|
|
||||||
|
class JvmSyntheticApplicabilityChecker : DeclarationChecker {
|
||||||
|
|
||||||
|
override fun check(declaration: KtDeclaration, descriptor: DeclarationDescriptor,
|
||||||
|
diagnosticHolder: DiagnosticSink, bindingContext: BindingContext
|
||||||
|
) {
|
||||||
|
val annotation = descriptor.findJvmSyntheticAnnotation() ?: return
|
||||||
|
if (declaration is KtProperty && declaration.hasDelegate()) {
|
||||||
|
val annotationEntry = DescriptorToSourceUtils.getSourceFromAnnotation(annotation) ?: return
|
||||||
|
diagnosticHolder.report(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE.on(annotationEntry))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
+2
@@ -102,6 +102,8 @@ public class DefaultErrorMessagesJvm implements DefaultErrorMessages.Extension {
|
|||||||
|
|
||||||
MAP.put(ErrorsJvm.INAPPLICABLE_JVM_FIELD, "{0}", Renderers.TO_STRING);
|
MAP.put(ErrorsJvm.INAPPLICABLE_JVM_FIELD, "{0}", Renderers.TO_STRING);
|
||||||
|
|
||||||
|
MAP.put(ErrorsJvm.JVM_SYNTHETIC_ON_DELEGATE, "''@JvmSynthetic'' annotation cannot be used on delegated properties");
|
||||||
|
|
||||||
MAP.put(ErrorsJvm.SUPER_CALL_WITH_DEFAULT_PARAMETERS, "Super-calls with default arguments are not allowed. Please specify all arguments of ''super.{0}'' explicitly", Renderers.TO_STRING);
|
MAP.put(ErrorsJvm.SUPER_CALL_WITH_DEFAULT_PARAMETERS, "Super-calls with default arguments are not allowed. Please specify all arguments of ''super.{0}'' explicitly", Renderers.TO_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -51,6 +51,8 @@ public interface ErrorsJvm {
|
|||||||
|
|
||||||
DiagnosticFactory1<KtAnnotationEntry, String> INAPPLICABLE_JVM_FIELD = DiagnosticFactory1.create(ERROR);
|
DiagnosticFactory1<KtAnnotationEntry, String> INAPPLICABLE_JVM_FIELD = DiagnosticFactory1.create(ERROR);
|
||||||
|
|
||||||
|
DiagnosticFactory0<KtAnnotationEntry> JVM_SYNTHETIC_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||||
|
|
||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_VALUE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> VOLATILE_ON_DELEGATE = DiagnosticFactory0.create(ERROR);
|
||||||
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
DiagnosticFactory0<KtAnnotationEntry> SYNCHRONIZED_ON_ABSTRACT = DiagnosticFactory0.create(ERROR);
|
||||||
|
|||||||
+2
-1
@@ -41,7 +41,8 @@ object JvmPlatformConfigurator : PlatformConfigurator(
|
|||||||
NativeFunChecker(),
|
NativeFunChecker(),
|
||||||
OverloadsAnnotationChecker(),
|
OverloadsAnnotationChecker(),
|
||||||
JvmFieldApplicabilityChecker(),
|
JvmFieldApplicabilityChecker(),
|
||||||
TypeParameterBoundIsNotArrayChecker()
|
TypeParameterBoundIsNotArrayChecker(),
|
||||||
|
JvmSyntheticApplicabilityChecker()
|
||||||
),
|
),
|
||||||
|
|
||||||
additionalCallCheckers = listOf(
|
additionalCallCheckers = listOf(
|
||||||
|
|||||||
@@ -33,11 +33,10 @@ fun DeclarationDescriptor.hasJvmStaticAnnotation(): Boolean {
|
|||||||
|
|
||||||
private val JVM_SYNTHETIC_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmSynthetic")
|
private val JVM_SYNTHETIC_ANNOTATION_FQ_NAME = FqName("kotlin.jvm.JvmSynthetic")
|
||||||
|
|
||||||
fun DeclarationDescriptor.hasJvmSyntheticAnnotation(): Boolean {
|
fun DeclarationDescriptor.hasJvmSyntheticAnnotation() = findJvmSyntheticAnnotation() != null
|
||||||
val jvmSyntheticName = JVM_SYNTHETIC_ANNOTATION_FQ_NAME
|
|
||||||
return annotations.findAnnotation(jvmSyntheticName) != null ||
|
fun DeclarationDescriptor.findJvmSyntheticAnnotation() =
|
||||||
Annotations.findUseSiteTargetedAnnotation(annotations, AnnotationUseSiteTarget.FIELD, jvmSyntheticName) != null
|
DescriptorUtils.getAnnotationByFqName(annotations, JVM_SYNTHETIC_ANNOTATION_FQ_NAME)
|
||||||
}
|
|
||||||
|
|
||||||
fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
fun CallableDescriptor.isPlatformStaticInObjectOrClass(): Boolean =
|
||||||
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClassOrEnumClass(it) }
|
isPlatformStaticIn { DescriptorUtils.isNonCompanionObject(it) || DescriptorUtils.isClassOrEnumClass(it) }
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ public final class Example {
|
|||||||
public final @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
|
public final @org.jetbrains.annotations.NotNull method getProp(): java.lang.String
|
||||||
public synthetic final method getProp2(): int
|
public synthetic final method getProp2(): int
|
||||||
public final method getUseSite(): int
|
public final method getUseSite(): int
|
||||||
public final method getUseSite2(): int
|
public synthetic final method getUseSite2(): int
|
||||||
public synthetic final method job(): void
|
public synthetic final method job(): void
|
||||||
public synthetic final method setProp2(p0: int): void
|
public synthetic final method setProp2(p0: int): void
|
||||||
public final method setUseSite2(p0: int): void
|
public synthetic final method setUseSite2(p0: int): void
|
||||||
}
|
}
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
import kotlin.properties.Delegates
|
||||||
|
|
||||||
|
class My {
|
||||||
|
<!JVM_SYNTHETIC_ON_DELEGATE!>@delegate:JvmSynthetic<!> val s: String by lazy { "s" }
|
||||||
|
|
||||||
|
// Both Ok
|
||||||
|
@get:JvmSynthetic val t: String by lazy { "t" }
|
||||||
|
@set:JvmSynthetic var z: String by Delegates.observable("?") { prop, old, new -> old.hashCode() }
|
||||||
|
}
|
||||||
+11
@@ -0,0 +1,11 @@
|
|||||||
|
package
|
||||||
|
|
||||||
|
public final class My {
|
||||||
|
public constructor My()
|
||||||
|
@delegate:kotlin.jvm.JvmSynthetic() public final val s: kotlin.String
|
||||||
|
public final val t: kotlin.String
|
||||||
|
public final var z: kotlin.String
|
||||||
|
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||||
|
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||||
|
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||||
|
}
|
||||||
@@ -151,6 +151,12 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("JvmSyntheticOnDelegate.kt")
|
||||||
|
public void testJvmSyntheticOnDelegate() throws Exception {
|
||||||
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/JvmSyntheticOnDelegate.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("qualifiedCallValue.kt")
|
@TestMetadata("qualifiedCallValue.kt")
|
||||||
public void testQualifiedCallValue() throws Exception {
|
public void testQualifiedCallValue() throws Exception {
|
||||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.kt");
|
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/annotations/qualifiedCallValue.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user