JS: prohibited extension function arguments in external functions; removed extension receiver in jQuery declarations.
This commit is contained in:
Vendored
+25
@@ -0,0 +1,25 @@
|
||||
external fun foo(<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>f: Int.() -> Int<!>)
|
||||
|
||||
external fun bar(<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>vararg f: Int.() -> Int<!>)
|
||||
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>external fun baz(): Int.() -> Int<!>
|
||||
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>external val prop: Int.() -> Int<!>
|
||||
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>external var prop2: Int.() -> Int<!>
|
||||
|
||||
external val propGet
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>get(): Int.() -> Int<!> = definedExternally
|
||||
|
||||
external var propSet
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>get(): Int.() -> Int<!> = definedExternally
|
||||
set(<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>v: Int.() -> Int<!>) = definedExternally
|
||||
|
||||
external class A(<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>f: Int.() -> Int<!>)
|
||||
|
||||
external data class <!WRONG_EXTERNAL_DECLARATION!>B(
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>val a: Int.() -> Int<!>,
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>var b: Int.() -> Int<!>
|
||||
)<!> {
|
||||
<!EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION!>val c: Int.() -> Int<!>
|
||||
}
|
||||
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
package
|
||||
|
||||
public external val prop: kotlin.Int.() -> kotlin.Int
|
||||
public external var prop2: kotlin.Int.() -> kotlin.Int
|
||||
public external val propGet: kotlin.Int.() -> kotlin.Int
|
||||
public external var propSet: kotlin.Int.() -> kotlin.Int
|
||||
public external fun bar(/*0*/ vararg f: kotlin.Int.() -> kotlin.Int /*kotlin.Array<out kotlin.Int.() -> kotlin.Int>*/): kotlin.Unit
|
||||
public external fun baz(): kotlin.Int.() -> kotlin.Int
|
||||
public external fun foo(/*0*/ f: kotlin.Int.() -> kotlin.Int): kotlin.Unit
|
||||
|
||||
public external final class A {
|
||||
public constructor A(/*0*/ f: kotlin.Int.() -> kotlin.Int)
|
||||
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
|
||||
}
|
||||
|
||||
public external final data class B {
|
||||
public constructor B(/*0*/ a: kotlin.Int.() -> kotlin.Int, /*1*/ b: kotlin.Int.() -> kotlin.Int)
|
||||
public final val a: kotlin.Int.() -> kotlin.Int
|
||||
public final var b: kotlin.Int.() -> kotlin.Int
|
||||
public final val c: kotlin.Int.() -> kotlin.Int
|
||||
public final operator /*synthesized*/ fun component1(): kotlin.Int.() -> kotlin.Int
|
||||
public final operator /*synthesized*/ fun component2(): kotlin.Int.() -> kotlin.Int
|
||||
public final /*synthesized*/ fun copy(/*0*/ a: kotlin.Int.() -> kotlin.Int = ..., /*1*/ b: kotlin.Int.() -> kotlin.Int = ...): B
|
||||
public open override /*1*/ /*synthesized*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*synthesized*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*synthesized*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -656,6 +656,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("extensionFunctionArgumentOrReturnType.kt")
|
||||
public void testExtensionFunctionArgumentOrReturnType() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/extensionFunctionArgumentOrReturnType.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("externalInterfaceNested.kt")
|
||||
public void testExternalInterfaceNested() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/native/externalInterfaceNested.kt");
|
||||
|
||||
+1
@@ -38,6 +38,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.JSCODE_NO_JAVASCRIPT_PRODUCED, "Argument must be non-empty JavaScript code")
|
||||
put(ErrorsJs.NESTED_EXTERNAL_DECLARATION, "Non top-level `external` declaration")
|
||||
put(ErrorsJs.WRONG_EXTERNAL_DECLARATION, "Declaration of such kind ({0}) can't be external", Renderers.STRING)
|
||||
put(ErrorsJs.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION, "Function types with receiver are prohibited in external declarations")
|
||||
|
||||
put(ErrorsJs.JS_NAME_CLASH, "JavaScript name ({0}) generated for this declaration clashes with another declaration: {1}",
|
||||
Renderers.STRING, Renderers.COMPACT)
|
||||
|
||||
@@ -40,6 +40,7 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory1<KtElement, KtElement> NOT_SUPPORTED = DiagnosticFactory1.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory0<KtExpression> JSCODE_NO_JAVASCRIPT_PRODUCED = DiagnosticFactory0.create(ERROR, DEFAULT);
|
||||
DiagnosticFactory1<KtExpression, String> WRONG_EXTERNAL_DECLARATION = DiagnosticFactory1.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtExpression> EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
DiagnosticFactory0<KtExpression> NESTED_EXTERNAL_DECLARATION = DiagnosticFactory0.create(ERROR, DECLARATION_SIGNATURE_OR_DEFAULT);
|
||||
|
||||
DiagnosticFactory2<KtElement, String, DeclarationDescriptor> JS_NAME_CLASH = DiagnosticFactory2.create(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.js.resolve.diagnostics
|
||||
|
||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||
import org.jetbrains.kotlin.builtins.isExtensionFunctionType
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
|
||||
import org.jetbrains.kotlin.js.PredefinedAnnotation
|
||||
@@ -29,6 +30,7 @@ import org.jetbrains.kotlin.resolve.DescriptorUtils
|
||||
import org.jetbrains.kotlin.resolve.calls.callUtil.getResolvedCall
|
||||
import org.jetbrains.kotlin.resolve.checkers.SimpleDeclarationChecker
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.*
|
||||
import org.jetbrains.kotlin.resolve.source.getPsi
|
||||
import org.jetbrains.kotlin.types.TypeUtils
|
||||
import org.jetbrains.kotlin.utils.singletonOrEmptyList
|
||||
|
||||
@@ -90,6 +92,23 @@ object JsExternalChecker : SimpleDeclarationChecker {
|
||||
diagnosticHolder.report(ErrorsJs.INLINE_EXTERNAL_DECLARATION.on(declaration))
|
||||
}
|
||||
|
||||
if (descriptor is CallableMemberDescriptor && !(descriptor is PropertyAccessorDescriptor && descriptor.isDefault)) {
|
||||
for (p in descriptor.valueParameters) {
|
||||
if ((p.varargElementType ?: p.type).isExtensionFunctionType) {
|
||||
val ktParam = p.source.getPsi() as? KtParameter ?: declaration
|
||||
diagnosticHolder.report(ErrorsJs.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION.on(ktParam))
|
||||
}
|
||||
}
|
||||
|
||||
// Only report on properties if there are no custom accessors
|
||||
val propertyWithCustomAccessors = descriptor is PropertyDescriptor &&
|
||||
!(descriptor.getter?.isDefault ?: true && descriptor.setter?.isDefault ?: true)
|
||||
|
||||
if (!propertyWithCustomAccessors && descriptor.returnType?.isExtensionFunctionType ?: false) {
|
||||
diagnosticHolder.report(ErrorsJs.EXTENSION_FUNCTION_IN_EXTERNAL_DECLARATION.on(declaration))
|
||||
}
|
||||
}
|
||||
|
||||
if (descriptor is CallableMemberDescriptor && descriptor.isNonAbstractMemberOfInterface() &&
|
||||
!descriptor.isNullableProperty()
|
||||
) {
|
||||
|
||||
@@ -5,14 +5,14 @@ import org.w3c.dom.Element
|
||||
@Deprecated("JQuery is going to be removed from the standard library")
|
||||
public external class JQuery() {
|
||||
public fun addClass(className: String): JQuery
|
||||
public fun addClass(f: Element.(Int, String) -> String): JQuery
|
||||
public fun addClass(f: (Int, String) -> String): JQuery
|
||||
|
||||
public fun attr(attrName: String): String
|
||||
public fun attr(attrName: String, value: String): JQuery
|
||||
|
||||
public fun html(): String
|
||||
public fun html(s: String): JQuery
|
||||
public fun html(f: Element.(Int, String) -> String): JQuery
|
||||
public fun html(f: (Int, String) -> String): JQuery
|
||||
|
||||
|
||||
public fun hasClass(className: String): Boolean
|
||||
@@ -22,22 +22,22 @@ public external class JQuery() {
|
||||
|
||||
public fun click(): JQuery
|
||||
|
||||
public fun mousedown(handler: Element.(MouseEvent) -> Unit): JQuery
|
||||
public fun mouseup(handler: Element.(MouseEvent) -> Unit): JQuery
|
||||
public fun mousemove(handler: Element.(MouseEvent) -> Unit): JQuery
|
||||
public fun mousedown(handler: (MouseEvent) -> Unit): JQuery
|
||||
public fun mouseup(handler: (MouseEvent) -> Unit): JQuery
|
||||
public fun mousemove(handler: (MouseEvent) -> Unit): JQuery
|
||||
|
||||
public fun dblclick(handler: Element.(MouseClickEvent) -> Unit): JQuery
|
||||
public fun click(handler: Element.(MouseClickEvent) -> Unit): JQuery
|
||||
public fun dblclick(handler: (MouseClickEvent) -> Unit): JQuery
|
||||
public fun click(handler: (MouseClickEvent) -> Unit): JQuery
|
||||
|
||||
public fun load(handler: Element.() -> Unit): JQuery
|
||||
public fun change(handler: Element.() -> Unit): JQuery
|
||||
public fun load(handler: () -> Unit): JQuery
|
||||
public fun change(handler: () -> Unit): JQuery
|
||||
|
||||
public fun append(str: String): JQuery
|
||||
public fun ready(handler: () -> Unit): JQuery
|
||||
public fun text(text: String): JQuery
|
||||
public fun slideUp(): JQuery
|
||||
public fun hover(handlerInOut: Element.() -> Unit): JQuery
|
||||
public fun hover(handlerIn: Element.() -> Unit, handlerOut: Element.() -> Unit): JQuery
|
||||
public fun hover(handlerInOut: () -> Unit): JQuery
|
||||
public fun hover(handlerIn: () -> Unit, handlerOut: () -> Unit): JQuery
|
||||
public fun next(): JQuery
|
||||
public fun parent(): JQuery
|
||||
public fun `val`(): String?
|
||||
|
||||
Reference in New Issue
Block a user