JS: prohibit referencing noImpl property from non-external declarations. See KT-15306
This commit is contained in:
@@ -42,7 +42,12 @@ object JsPlatformConfigurator : PlatformConfigurator(
|
||||
JsDynamicDeclarationChecker,
|
||||
HeaderImplDeclarationChecker()
|
||||
),
|
||||
additionalCallCheckers = listOf(ReifiedTypeParameterSubstitutionChecker(), JsModuleCallChecker, JsDynamicCallChecker),
|
||||
additionalCallCheckers = listOf(
|
||||
ReifiedTypeParameterSubstitutionChecker(),
|
||||
JsModuleCallChecker,
|
||||
JsDynamicCallChecker,
|
||||
JsNoImplCallChecker
|
||||
),
|
||||
additionalTypeCheckers = listOf(),
|
||||
additionalClassifierUsageCheckers = listOf(),
|
||||
additionalAnnotationCheckers = listOf(),
|
||||
|
||||
+1
@@ -94,6 +94,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.EXTERNAL_ANONYMOUS_INITIALIZER, "Anonymous initializer is not allowed in external classes")
|
||||
put(ErrorsJs.EXTERNAL_ENUM_ENTRY_WITH_BODY, "Entry of external enum class can't have body")
|
||||
put(ErrorsJs.EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER, "External class constructor cannot have a property parameter")
|
||||
put(ErrorsJs.CALL_TO_NO_IMPL_FROM_NON_EXTERNAL_DECLARATION, "This property can only be used from external declarations")
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
@@ -97,6 +97,7 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory0<KtAnonymousInitializer> EXTERNAL_ANONYMOUS_INITIALIZER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtClassBody> EXTERNAL_ENUM_ENTRY_WITH_BODY = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtParameter> EXTERNAL_CLASS_CONSTRUCTOR_PROPERTY_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<PsiElement> CALL_TO_NO_IMPL_FROM_NON_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* 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.js.resolve.diagnostics
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.js.resolve.diagnostics.JsExternalChecker.NO_IMPL_PROPERTY_NAME
|
||||
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallChecker
|
||||
import org.jetbrains.kotlin.resolve.calls.checkers.CallCheckerContext
|
||||
import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameUnsafe
|
||||
|
||||
object JsNoImplCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
if (resolvedCall.resultingDescriptor.fqNameUnsafe != NO_IMPL_PROPERTY_NAME) return
|
||||
|
||||
val ownerDescriptor = context.scope.ownerDescriptor
|
||||
if (!AnnotationsUtils.isNativeObject(ownerDescriptor) && !AnnotationsUtils.isPredefinedObject(ownerDescriptor)) {
|
||||
context.trace.report(ErrorsJs.CALL_TO_NO_IMPL_FROM_NON_EXTERNAL_DECLARATION.on(reportOn))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user