JS: prohibit using more than one argument in indexed access with dynamic receiver (see KT-6580)
This commit is contained in:
-2
@@ -14,9 +14,7 @@ public final fun contains(/*0*/ p0: dynamic): dynamic
|
||||
public final fun contains(/*0*/ p0: dynamic): dynamic
|
||||
public final fun contains(/*0*/ p0: dynamic): dynamic
|
||||
public final fun get(/*0*/ p0: dynamic): dynamic
|
||||
public final fun get(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
|
||||
public final fun set(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
|
||||
public final fun set(/*0*/ p0: dynamic, /*1*/ p1: dynamic, /*2*/ p2: dynamic): dynamic
|
||||
public final fun get(/*0*/ p0: dynamic): dynamic
|
||||
public final fun inc(): dynamic
|
||||
public final fun inc(): dynamic
|
||||
|
||||
@@ -27,10 +27,8 @@ fun test(d: dynamic) {
|
||||
1 <!DEBUG_INFO_DYNAMIC!>!in<!> d
|
||||
|
||||
<!DEBUG_INFO_DYNAMIC!>d[1]<!>
|
||||
<!DEBUG_INFO_DYNAMIC!>d[1, 2]<!>
|
||||
|
||||
<!DEBUG_INFO_DYNAMIC!>d[1]<!> = 2
|
||||
<!DEBUG_INFO_DYNAMIC!>d[1, 2]<!> = 3
|
||||
|
||||
<!DEBUG_INFO_DYNAMIC!>d[1]<!><!DEBUG_INFO_DYNAMIC!>++<!>
|
||||
<!DEBUG_INFO_DYNAMIC!>++<!><!DEBUG_INFO_DYNAMIC!>d[1]<!>
|
||||
|
||||
+4
@@ -0,0 +1,4 @@
|
||||
public final fun get(/*0*/ p0: dynamic): dynamic
|
||||
public final fun get(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
|
||||
public final fun set(/*0*/ p0: dynamic, /*1*/ p1: dynamic): dynamic
|
||||
public final fun set(/*0*/ p0: dynamic, /*1*/ p1: dynamic, /*2*/ p2: dynamic): dynamic
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo() {
|
||||
val a: dynamic = Any()
|
||||
println(a[0])
|
||||
println(<!WRONG_OPERATION_WITH_DYNAMIC!>a[0, 1]<!>)
|
||||
|
||||
a[0] = 23
|
||||
<!WRONG_OPERATION_WITH_DYNAMIC!>a[0, 1]<!> = 42
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(): kotlin.Unit
|
||||
@@ -146,6 +146,12 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("indexedAccess.kt")
|
||||
public void testIndexedAccess() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/indexedAccess.kt");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("inference.kt")
|
||||
public void testInference() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithJsStdLib/dynamicTypes/inference.kt");
|
||||
|
||||
@@ -38,7 +38,7 @@ object JsPlatformConfigurator : PlatformConfigurator(
|
||||
PlatformImplDeclarationChecker(),
|
||||
JsExternalChecker()
|
||||
),
|
||||
additionalCallCheckers = listOf(ReifiedTypeParameterSubstitutionChecker(), JsModuleCallChecker),
|
||||
additionalCallCheckers = listOf(ReifiedTypeParameterSubstitutionChecker(), JsModuleCallChecker, JsDynamicCallChecker),
|
||||
additionalTypeCheckers = listOf(),
|
||||
additionalClassifierUsageCheckers = listOf(),
|
||||
additionalAnnotationCheckers = listOf(),
|
||||
|
||||
+1
@@ -62,6 +62,7 @@ private val DIAGNOSTIC_FACTORY_TO_RENDERER by lazy {
|
||||
put(ErrorsJs.CANNOT_CHECK_FOR_NATIVE_INTERFACE, "Cannot check for native interface: {0}", RENDER_TYPE)
|
||||
put(ErrorsJs.UNCHECKED_CAST_TO_NATIVE_INTERFACE, "Unchecked cast to native interface: {0} to {1}", RENDER_TYPE, RENDER_TYPE)
|
||||
put(ErrorsJs.NATIVE_INTERFACE_AS_REIFIED_TYPE_ARGUMENT, "Cannot pass native interface {0} for reified type parameter", RENDER_TYPE)
|
||||
put(ErrorsJs.WRONG_OPERATION_WITH_DYNAMIC, "Wrong operation with dynamic value: {0}", Renderers.STRING)
|
||||
|
||||
this
|
||||
}
|
||||
|
||||
@@ -61,6 +61,7 @@ public interface ErrorsJs {
|
||||
DiagnosticFactory1<PsiElement, KotlinType> CANNOT_CHECK_FOR_NATIVE_INTERFACE = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory2<PsiElement, KotlinType, KotlinType> UNCHECKED_CAST_TO_NATIVE_INTERFACE = DiagnosticFactory2.create(WARNING);
|
||||
DiagnosticFactory1<PsiElement, KotlinType> NATIVE_INTERFACE_AS_REIFIED_TYPE_ARGUMENT = DiagnosticFactory1.create(ERROR);
|
||||
DiagnosticFactory1<PsiElement, String> WRONG_OPERATION_WITH_DYNAMIC = DiagnosticFactory1.create(ERROR);
|
||||
|
||||
@SuppressWarnings("UnusedDeclaration")
|
||||
Object _initializer = new Object() {
|
||||
|
||||
+36
@@ -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.psi.KtArrayAccessExpression
|
||||
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.types.isDynamic
|
||||
|
||||
object JsDynamicCallChecker : CallChecker {
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val callee = resolvedCall.resultingDescriptor
|
||||
if (callee.dispatchReceiverParameter?.type?.isDynamic() != true) return
|
||||
|
||||
val element = resolvedCall.call.callElement
|
||||
if (element is KtArrayAccessExpression && element.indexExpressions.size > 1) {
|
||||
context.trace.report(ErrorsJs.WRONG_OPERATION_WITH_DYNAMIC.on(reportOn, "indexed access with more than one index"))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user