JS: split error diagnostic about body of external declaration into three different diagnostics (additional ones: wrong initializer, wrong default value of parameter).
This commit is contained in:
@@ -8,7 +8,7 @@ external fun baz(): Int = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
|
||||
|
||||
external fun f(x: Int, y: String = noImpl): Unit
|
||||
|
||||
external fun g(x: Int, y: String = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>""<!>): Unit
|
||||
external fun g(x: Int, y: String = <!WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER!>""<!>): Unit
|
||||
|
||||
external var a: Int
|
||||
get() = noImpl
|
||||
@@ -21,7 +21,7 @@ external val b: Int
|
||||
|
||||
external val c: Int = noImpl
|
||||
|
||||
external val d: Int = <!WRONG_BODY_OF_EXTERNAL_DECLARATION!>23<!>
|
||||
external val d: Int = <!WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION!>23<!>
|
||||
|
||||
external class C {
|
||||
fun foo(): Int = noImpl
|
||||
|
||||
+4
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -76,6 +76,9 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE,
|
||||
"Only nullable properties of external interfaces are allowed to be non-abstract")
|
||||
put(ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION, "Wrong body of external declaration. Must be either ' = noImpl' or { noImpl }")
|
||||
put(ErrorsJs.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION, "Wrong initializer of external declaration. Must be ' = noImpl'")
|
||||
put(ErrorsJs.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER,
|
||||
"Wrong default value for parameter of external function. Must be ' = noImpl'")
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2010-2015 JetBrains s.r.o.
|
||||
* 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.
|
||||
@@ -81,6 +81,8 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory0<KtExpression> NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE = DiagnosticFactory0.create(
|
||||
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtExpression> WRONG_BODY_OF_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR);
|
||||
DiagnosticFactory0<KtExpression> WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER = DiagnosticFactory0.create(ERROR);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
+12
-17
@@ -90,35 +90,30 @@ object JsExternalChecker : SimpleDeclarationChecker {
|
||||
diagnosticHolder.report(ErrorsJs.NON_ABSTRACT_MEMBER_OF_EXTERNAL_INTERFACE.on(declaration))
|
||||
}
|
||||
|
||||
checkBody(declaration, diagnosticHolder, bindingContext)
|
||||
checkBody(declaration, descriptor, diagnosticHolder, bindingContext)
|
||||
}
|
||||
|
||||
private fun checkBody(declaration: KtDeclaration, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) {
|
||||
private fun checkBody(
|
||||
declaration: KtDeclaration, descriptor: DeclarationDescriptor,
|
||||
diagnosticHolder: DiagnosticSink, bindingContext: BindingContext
|
||||
) {
|
||||
if (declaration is KtProperty && descriptor is PropertyAccessorDescriptor) return
|
||||
|
||||
if (declaration is KtDeclarationWithBody && !declaration.hasValidExternalBody(bindingContext)) {
|
||||
reportWrongBody(declaration.bodyExpression!!, diagnosticHolder, bindingContext)
|
||||
diagnosticHolder.report(ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION.on(declaration.bodyExpression!!))
|
||||
}
|
||||
else if (declaration is KtDeclarationWithInitializer && declaration.initializer?.isNoImplExpression(bindingContext) == false) {
|
||||
reportWrongBody(declaration.initializer!!, diagnosticHolder, bindingContext)
|
||||
diagnosticHolder.report(ErrorsJs.WRONG_INITIALIZER_OF_EXTERNAL_DECLARATION.on(declaration.initializer!!))
|
||||
}
|
||||
if (declaration is KtCallableDeclaration) {
|
||||
for (defaultValue in declaration.valueParameters.mapNotNull { it.defaultValue }) {
|
||||
checkExternalExpression(defaultValue, diagnosticHolder, bindingContext)
|
||||
if (!defaultValue.isNoImplExpression(bindingContext)) {
|
||||
diagnosticHolder.report(ErrorsJs.WRONG_DEFAULT_VALUE_FOR_EXTERNAL_FUN_PARAMETER.on(defaultValue))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun checkExternalExpression(expression: KtExpression, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) {
|
||||
if (!expression.isNoImplExpression(bindingContext)) {
|
||||
reportWrongBody(expression, diagnosticHolder, bindingContext)
|
||||
}
|
||||
}
|
||||
|
||||
private fun reportWrongBody(expression: KtExpression, diagnosticHolder: DiagnosticSink, bindingContext: BindingContext) {
|
||||
if (bindingContext.diagnostics.forElement(expression).none { it.factory == ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION }) {
|
||||
diagnosticHolder.report(ErrorsJs.WRONG_BODY_OF_EXTERNAL_DECLARATION.on(expression))
|
||||
}
|
||||
}
|
||||
|
||||
private fun isDirectlyExternal(declaration: KtDeclaration, descriptor: DeclarationDescriptor): Boolean {
|
||||
if (declaration is KtProperty && descriptor is PropertyAccessorDescriptor) return false
|
||||
|
||||
|
||||
Reference in New Issue
Block a user