JS: prohibit inline external declarations. See KT-15307

This commit is contained in:
Alexey Andreev
2016-12-19 14:06:14 +03:00
parent 84f094c770
commit 403753f5b5
7 changed files with 49 additions and 1 deletions
@@ -0,0 +1,19 @@
// !DIAGNOSTICS: -NOTHING_TO_INLINE
<!INLINE_EXTERNAL_DECLARATION!>inline external fun foo(): Unit<!>
inline external val bar: Int
<!INLINE_EXTERNAL_DECLARATION!>get()<!> = noImpl
external val baz: Int
<!INLINE_EXTERNAL_DECLARATION!>inline get()<!> = noImpl
external class A {
<!INLINE_EXTERNAL_DECLARATION!>inline fun foo(): Unit<!>
inline val bar: Int
<!INLINE_EXTERNAL_DECLARATION!>get()<!> = noImpl
val baz: Int
<!INLINE_EXTERNAL_DECLARATION!>inline get()<!> = noImpl
}
@@ -0,0 +1,15 @@
package
public external val bar: kotlin.Int
public external val baz: kotlin.Int
public external inline fun foo(): kotlin.Unit
public external final class A {
public constructor A()
public final val bar: kotlin.Int
public final val baz: kotlin.Int
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public final inline fun foo(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
@@ -581,6 +581,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
doTest(fileName);
}
@TestMetadata("inline.kt")
public void testInline() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/inline.kt");
doTest(fileName);
}
@TestMetadata("innerClass.kt")
public void testInnerClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/innerClass.kt");
@@ -72,6 +72,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
put(ErrorsJs.OVERRIDING_EXTERNAL_FUN_WITH_OPTIONAL_PARAMS_WITH_FAKE,
"Overriding `external` function with optional parameters by declaration from superclass: {0}", Renderers.COMPACT)
put(ErrorsJs.IMPLEMENTING_FUNCTION_INTERFACE, "Implementing function interface is prohibited in JavaScript")
put(ErrorsJs.INLINE_EXTERNAL_DECLARATION, "Inline external declaration")
this
}
@@ -76,6 +76,8 @@ public interface ErrorsJs {
DiagnosticFactory1.create(ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<KtClassOrObject> IMPLEMENTING_FUNCTION_INTERFACE = DiagnosticFactory0.create(
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
DiagnosticFactory0<KtDeclaration> INLINE_EXTERNAL_DECLARATION = DiagnosticFactory0.create(
ERROR, PositioningStrategies.DECLARATION_SIGNATURE_OR_DEFAULT);
@SuppressWarnings("UnusedDeclaration")
Object _initializer = new Object() {
@@ -18,6 +18,7 @@ package org.jetbrains.kotlin.js.resolve.diagnostics
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.annotations.isInlineOnlyOrReified
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.js.PredefinedAnnotation
import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils
@@ -75,6 +76,10 @@ object JsExternalChecker : SimpleDeclarationChecker {
diagnosticHolder.report(ErrorsJs.EXTERNAL_TYPE_EXTENDS_NON_EXTERNAL_TYPE.on(declaration))
}
}
if (descriptor is FunctionDescriptor && descriptor.isInline) {
diagnosticHolder.report(ErrorsJs.INLINE_EXTERNAL_DECLARATION.on(declaration))
}
}
private fun isDirectlyExternal(declaration: KtDeclaration, descriptor: DeclarationDescriptor): Boolean {
+1 -1
View File
@@ -35,4 +35,4 @@ public annotation class Volatile
@Retention(AnnotationRetention.SOURCE)
public annotation class Synchronized
public external inline fun <R> synchronized(lock: Any, crossinline block: () -> R): R = block()
public inline fun <R> synchronized(lock: Any, crossinline block: () -> R): R = block()