Drop YIELD_IS_RESERVED diagnostic in 1.7.0 #KT-27750 Fixed

This commit is contained in:
Mikhail Glukhikh
2021-10-21 10:35:11 +03:00
committed by teamcity
parent 0739925869
commit 61e0375900
22 changed files with 348 additions and 12 deletions
@@ -644,6 +644,18 @@ public class DiagnosisCompilerTestFE10TestdataTestGenerated extends AbstractDiag
runTest("compiler/testData/diagnostics/tests/ReserveYield2.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore.kt")
public void testReserveYieldNoMore() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore2.kt")
public void testReserveYieldNoMore2() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore2.kt");
}
@Test
@TestMetadata("ResolveOfJavaGenerics.kt")
public void testResolveOfJavaGenerics() throws Exception {
@@ -644,6 +644,18 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/ReserveYield2.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore.kt")
public void testReserveYieldNoMore() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore2.kt")
public void testReserveYieldNoMore2() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore2.kt");
}
@Test
@TestMetadata("ResolveOfJavaGenerics.kt")
public void testResolveOfJavaGenerics() throws Exception {
@@ -644,6 +644,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/ReserveYield2.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore.kt")
public void testReserveYieldNoMore() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore2.kt")
public void testReserveYieldNoMore2() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore2.kt");
}
@Test
@TestMetadata("ResolveOfJavaGenerics.kt")
public void testResolveOfJavaGenerics() throws Exception {
@@ -25,6 +25,7 @@ import org.jetbrains.kotlin.cfg.pseudocode.instructions.eval.MagicKind.*
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ConditionalJumpInstruction
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ReturnValueInstruction
import org.jetbrains.kotlin.cfg.pseudocode.instructions.jumps.ThrowExceptionInstruction
import org.jetbrains.kotlin.config.LanguageVersionSettingsImpl
import org.jetbrains.kotlin.descriptors.*
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
import org.jetbrains.kotlin.psi.*
@@ -115,7 +116,9 @@ fun getExpectedTypePredicate(
TracingStrategy.EMPTY,
DataFlowInfoForArgumentsImpl(DataFlowInfo.EMPTY, call)
)
val status = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(call, TracingStrategy.EMPTY, candidateCall)
val status = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(
call, TracingStrategy.EMPTY, candidateCall, LanguageVersionSettingsImpl.DEFAULT
)
if (!status.isSuccess) continue
val candidateArgumentMap = candidateCall.valueArguments
@@ -255,7 +255,9 @@ class TypeResolver(
val referenceExpression = type.referenceExpression ?: return
checkReservedYield(referenceExpression, c.trace)
if (!languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
checkReservedYield(referenceExpression, c.trace)
}
c.trace.record(BindingContext.REFERENCE_TARGET, referenceExpression, classifier)
result = resolveTypeForClassifier(c, classifier, qualifierResolutionResult, type, annotations)
@@ -138,7 +138,7 @@ class CandidateResolver(
private fun <D : CallableDescriptor> CallCandidateResolutionContext<D>.mapArguments() = check {
val argumentMappingStatus = ValueArgumentsToParametersMapper.mapValueArgumentsToParameters(
call, tracing, candidateCall
call, tracing, candidateCall, languageVersionSettings
)
if (!argumentMappingStatus.isSuccess) {
candidateCall.addStatus(ARGUMENTS_MAPPING_ERROR)
@@ -21,6 +21,8 @@ import kotlin.collections.CollectionsKt;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.kotlin.builtins.functions.FunctionInvokeDescriptor;
import org.jetbrains.kotlin.config.LanguageFeature;
import org.jetbrains.kotlin.config.LanguageVersionSettings;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.diagnostics.Diagnostic;
import org.jetbrains.kotlin.name.Name;
@@ -66,10 +68,11 @@ public class ValueArgumentsToParametersMapper {
public static <D extends CallableDescriptor> Status mapValueArgumentsToParameters(
@NotNull Call call,
@NotNull TracingStrategy tracing,
@NotNull MutableResolvedCall<D> candidateCall
@NotNull MutableResolvedCall<D> candidateCall,
@NotNull LanguageVersionSettings languageVersionSettings
) {
//return new ValueArgumentsToParametersMapper().process(call, tracing, candidateCall, unmappedArguments);
Processor<D> processor = new Processor<>(call, candidateCall, tracing);
Processor<D> processor = new Processor<>(call, candidateCall, tracing, languageVersionSettings);
processor.process();
return processor.status;
}
@@ -78,6 +81,7 @@ public class ValueArgumentsToParametersMapper {
private final Call call;
private final TracingStrategy tracing;
private final MutableResolvedCall<D> candidateCall;
private final LanguageVersionSettings languageVersionSettings;
private final List<ValueParameterDescriptor> parameters;
private final Map<Name,ValueParameterDescriptor> parameterByName;
@@ -87,11 +91,17 @@ public class ValueArgumentsToParametersMapper {
private final Set<ValueParameterDescriptor> usedParameters = new HashSet<>();
private Status status = OK;
private Processor(@NotNull Call call, @NotNull MutableResolvedCall<D> candidateCall, @NotNull TracingStrategy tracing) {
private Processor(
@NotNull Call call,
@NotNull MutableResolvedCall<D> candidateCall,
@NotNull TracingStrategy tracing,
@NotNull LanguageVersionSettings languageVersionSettings
) {
this.call = call;
this.tracing = tracing;
this.candidateCall = candidateCall;
this.parameters = candidateCall.getCandidateDescriptor().getValueParameters();
this.languageVersionSettings = languageVersionSettings;
this.parameterByName = new HashMap<>();
for (ValueParameterDescriptor valueParameter : parameters) {
@@ -177,7 +187,9 @@ public class ValueArgumentsToParametersMapper {
ValueParameterDescriptor valueParameterDescriptor = parameterByName.get(argumentName.getAsName());
KtSimpleNameExpression nameReference = argumentName.getReferenceExpression();
ReservedCheckingKt.checkReservedYield(nameReference, candidateCall.getTrace());
if (!languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
ReservedCheckingKt.checkReservedYield(nameReference, candidateCall.getTrace());
}
if (nameReference != null) {
if (candidate instanceof MemberDescriptor && ((MemberDescriptor) candidate).isExpect() &&
candidate.getContainingDeclaration() instanceof ClassDescriptor) {
@@ -166,7 +166,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
@Override
public KotlinTypeInfo visitSimpleNameExpression(@NotNull KtSimpleNameExpression expression, ExpressionTypingContext context) {
ReservedCheckingKt.checkReservedYield(expression, context.trace);
if (!components.languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
ReservedCheckingKt.checkReservedYield(expression, context.trace);
}
// TODO : other members
// TODO : type substitutions???
@@ -884,7 +886,9 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
boolean isStatement
) {
KtSimpleNameExpression labelExpression = expression.getTargetLabel();
ReservedCheckingKt.checkReservedYield(labelExpression, context.trace);
if (!components.languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
ReservedCheckingKt.checkReservedYield(labelExpression, context.trace);
}
if (labelExpression != null) {
PsiElement labelIdentifier = labelExpression.getIdentifier();
UnderscoreChecker.INSTANCE.checkIdentifier(labelIdentifier, context.trace, components.languageVersionSettings);
@@ -743,7 +743,9 @@ class DoubleColonExpressionResolver(
return when {
resolutionResults.isNothing -> null
else -> ResolutionResultsAndTraceCommitCallback(resolutionResults) {
checkReservedYield(reference, outerContext.trace)
if (!languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
checkReservedYield(reference, outerContext.trace)
}
if (resolutionMode != ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS || resolutionResults.isSuccess) {
temporaryTrace.commit()
}
@@ -149,7 +149,9 @@ internal class FunctionsTypingVisitor(facade: ExpressionTypingInternals) : Expre
}
override fun visitLambdaExpression(expression: KtLambdaExpression, context: ExpressionTypingContext): KotlinTypeInfo? {
checkReservedYieldBeforeLambda(expression, context.trace)
if (!components.languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
checkReservedYieldBeforeLambda(expression, context.trace)
}
if (!expression.functionLiteral.hasBody()) return null
val expectedType = context.expectedType
@@ -116,7 +116,9 @@ object LabelResolver {
fun resolveControlLabel(expression: KtExpressionWithLabel, context: ResolutionContext<*>): KtElement? {
val labelElement = expression.getTargetLabel()
checkReservedYield(labelElement, context.trace)
if (!context.languageVersionSettings.supportsFeature(LanguageFeature.YieldIsNoMoreReserved)) {
checkReservedYield(labelElement, context.trace)
}
val labelName = expression.getLabelNameAsName()
if (labelElement == null || labelName == null) return null
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE
// !LANGUAGE: -YieldIsNoMoreReserved
// FILE: 1.kt
package p1.yield
+1
View File
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE
// !LANGUAGE: -YieldIsNoMoreReserved
// FILE: 1.kt
package p1.yield
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION
// !LANGUAGE: -YieldIsNoMoreReserved
// FILE: 1.kt
+1
View File
@@ -1,4 +1,5 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION
// !LANGUAGE: -YieldIsNoMoreReserved
// FILE: 1.kt
@@ -0,0 +1,72 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE
// !LANGUAGE: +YieldIsNoMoreReserved
// FILE: 1.kt
package p1.yield
import p1.yield.yield
import p1.yield.foo
val yield = 5
fun foo(){}
fun bar(yield: Int = 4) {}
fun yield(yield: Int) {
"$yield"
"${yield}"
yield
val foo = yield + yield
val foo2 = yield
bar(yield = 5)
yield(4)
yield {}
class yield<T: yield<T>>
return@yield
return@yield Unit
val foo5: yield<*>
}
fun yield(i: (Int) -> Unit) {}
// FILE: 2.kt
package p2.yield
import p2.yield.yield
import p2.yield.foo
val yield = 5
fun foo(){}
fun bar(yield: Int = 4) {}
fun yield(yield: Int) {
"$`yield`"
"${`yield`}"
`yield`
val foo = `yield` + `yield`
val foo2 = `yield`
bar(`yield` = 5)
`yield`(4)
`yield` {}
class `yield`<T: `yield`<T>>
return@`yield`
return@`yield` Unit
val foo5: `yield`<*>
}
fun yield(i: (Int) -> Unit) {}
@@ -0,0 +1,23 @@
package
package p1 {
package p1.yield {
public val yield: kotlin.Int = 5
public fun bar(/*0*/ yield: kotlin.Int = ...): kotlin.Unit
public fun foo(): kotlin.Unit
public fun yield(/*0*/ i: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
public fun yield(/*0*/ yield: kotlin.Int): kotlin.Unit
}
}
package p2 {
package p2.yield {
public val yield: kotlin.Int = 5
public fun bar(/*0*/ yield: kotlin.Int = ...): kotlin.Unit
public fun foo(): kotlin.Unit
public fun yield(/*0*/ i: (kotlin.Int) -> kotlin.Unit): kotlin.Unit
public fun yield(/*0*/ yield: kotlin.Int): kotlin.Unit
}
}
@@ -0,0 +1,55 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION
// !LANGUAGE: +YieldIsNoMoreReserved
// FILE: 1.kt
annotation class yield
fun bar(p: Int) {
yield@ p
`yield`@ p
@yield() p
@`yield`() p
for (yield in 1..5) {
}
{ yield: Int -> }
val (yield) = listOf(4)
}
fun <T> listOf(vararg e: T): List<T> = null!!
operator fun <T> List<T>.component1() = get(0)
// FILE: 2.kt
package p3
enum class yield {
yield
}
fun f1(yield: Int, foo: Int = yield) {}
fun f2(foo: yield) {}
// FILE: 3.kt
package p4
typealias yield = Number
fun <yield: Number> f1() {}
fun <y: yield> f2() {}
// FILE: 4.kt
object X {
fun yield() {}
fun test3(yield: Int) {
X::yield
yield::toInt
}
}
@@ -0,0 +1,55 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_EXPRESSION -UNREACHABLE_CODE -UNUSED_VARIABLE -WRONG_ANNOTATION_TARGET -UNUSED_LAMBDA_EXPRESSION
// !LANGUAGE: +YieldIsNoMoreReserved
// FILE: 1.kt
annotation class yield
fun bar(p: Int) {
<!REDUNDANT_LABEL_WARNING!>yield@<!> p
<!REDUNDANT_LABEL_WARNING!>`yield`@<!> p
@yield() p
@`yield`() p
for (yield in 1..5) {
}
{ yield: Int -> }
val (yield) = listOf(4)
}
fun <T> listOf(vararg e: T): List<T> = null!!
operator fun <T> List<T>.component1() = get(0)
// FILE: 2.kt
package p3
enum class yield {
yield
}
fun f1(yield: Int, foo: Int = yield) {}
fun f2(foo: yield) {}
// FILE: 3.kt
package p4
typealias yield = Number
fun <yield: Number> f1() {}
fun <y: yield> f2() {}
// FILE: 4.kt
object X {
fun yield() {}
fun test3(yield: Int) {
X::yield
yield::toInt
}
}
@@ -0,0 +1,51 @@
package
public fun bar(/*0*/ p: kotlin.Int): kotlin.Unit
public fun </*0*/ T> listOf(/*0*/ vararg e: T /*kotlin.Array<out T>*/): kotlin.collections.List<T>
public operator fun </*0*/ T> kotlin.collections.List<T>.component1(): T
public object X {
private constructor X()
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 final fun test3(/*0*/ yield: kotlin.Int): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public final fun yield(): kotlin.Unit
}
public final annotation class yield : kotlin.Annotation {
public constructor yield()
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
}
package p3 {
public fun f1(/*0*/ yield: kotlin.Int, /*1*/ foo: kotlin.Int = ...): kotlin.Unit
public fun f2(/*0*/ foo: p3.yield): kotlin.Unit
public final enum class yield : kotlin.Enum<p3.yield> {
enum entry yield
private constructor yield()
public final override /*1*/ /*fake_override*/ val name: kotlin.String
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: p3.yield): kotlin.Int
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
protected/*protected and package*/ final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun finalize(): kotlin.Unit
public final override /*1*/ /*fake_override*/ /*isHiddenForResolutionEverywhereBesideSupercalls*/ fun getDeclaringClass(): java.lang.Class<p3.yield!>!
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
// Static members
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): p3.yield
public final /*synthesized*/ fun values(): kotlin.Array<p3.yield>
}
}
package p4 {
public fun </*0*/ yield : kotlin.Number> f1(): kotlin.Unit
public fun </*0*/ y : p4.yield /* = kotlin.Number */> f2(): kotlin.Unit
public typealias yield = kotlin.Number
}
@@ -644,6 +644,18 @@ public class DiagnosticTestGenerated extends AbstractDiagnosticTest {
runTest("compiler/testData/diagnostics/tests/ReserveYield2.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore.kt")
public void testReserveYieldNoMore() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore.kt");
}
@Test
@TestMetadata("ReserveYieldNoMore2.kt")
public void testReserveYieldNoMore2() throws Exception {
runTest("compiler/testData/diagnostics/tests/ReserveYieldNoMore2.kt");
}
@Test
@TestMetadata("ResolveOfJavaGenerics.kt")
public void testResolveOfJavaGenerics() throws Exception {
@@ -245,6 +245,7 @@ enum class LanguageFeature(
ProperInternalVisibilityCheckInImportingScope(KOTLIN_1_7, kind = BUG_FIX),
InlineClassImplementationByDelegation(KOTLIN_1_7),
QualifiedSupertypeMayBeExtendedByOtherSupertype(KOTLIN_1_7),
YieldIsNoMoreReserved(KOTLIN_1_7),
// 1.8