[FIR][LightTree] Generate and fix missing tests

Add TYPE_PARAMETERS_LIST positioning
Use whole branch as source in when branches
This commit is contained in:
Andrey Zinovyev
2021-04-19 19:42:58 +03:00
committed by TeamCityServer
parent b9ae22207e
commit 2f7d6da22f
14 changed files with 156 additions and 19 deletions
@@ -1822,6 +1822,47 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/annotations/typeUse")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class TypeUse {
@Test
public void testAllFilesPresentInTypeUse() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/tests/annotations/typeUse"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("kt19455.kt")
public void testKt19455() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt19455.kt");
}
@Test
@TestMetadata("kt25876.kt")
public void testKt25876() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt25876.kt");
}
@Test
@TestMetadata("kt46173.kt")
public void testKt46173() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt46173.kt");
}
@Test
@TestMetadata("kt8325.kt")
public void testKt8325() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/kt8325.kt");
}
@Test
@TestMetadata("nonTypeUseAnnotationOnType.kt")
public void testNonTypeUseAnnotationOnType() throws Exception {
runTest("compiler/testData/diagnostics/tests/annotations/typeUse/nonTypeUseAnnotationOnType.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/tests/annotations/withUseSiteTarget")
@TestDataPath("$PROJECT_ROOT")
@@ -4267,6 +4308,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/classObjects/resolveFunctionInsideClassObject.kt");
}
@Test
@TestMetadata("selfCallsInCompanionSuperConstructor_error.kt")
public void testSelfCallsInCompanionSuperConstructor_error() throws Exception {
runTest("compiler/testData/diagnostics/tests/classObjects/selfCallsInCompanionSuperConstructor_error.kt");
}
@Test
@TestMetadata("selfCallsInCompanionSuperConstructor_warning.kt")
public void testSelfCallsInCompanionSuperConstructor_warning() throws Exception {
runTest("compiler/testData/diagnostics/tests/classObjects/selfCallsInCompanionSuperConstructor_warning.kt");
}
@Test
@TestMetadata("typeParametersInAnnonymousObject.kt")
public void testTypeParametersInAnnonymousObject() throws Exception {
@@ -19249,6 +19302,18 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt");
}
@Test
@TestMetadata("newLiteralOperatorsResolution_newResolve.kt")
public void testNewLiteralOperatorsResolution_newResolve() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_newResolve.kt");
}
@Test
@TestMetadata("newLiteralOperatorsResolution_warning.kt")
public void testNewLiteralOperatorsResolution_warning() throws Exception {
runTest("compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.kt");
}
@Test
@TestMetadata("numberAsUnionAndIntersection.kt")
public void testNumberAsUnionAndIntersection() throws Exception {
@@ -31216,6 +31281,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt");
}
@Test
@TestMetadata("implicitNothingInDelegate.kt")
public void testImplicitNothingInDelegate() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/implicitNothingInDelegate.kt");
}
@Test
@TestMetadata("InaccessibleInternalClass.kt")
public void testInaccessibleInternalClass() throws Exception {
@@ -32748,6 +32819,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/compositions.kt");
}
@Test
@TestMetadata("contractWithDeepGenerics.kt")
public void testContractWithDeepGenerics() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/contracts/smartcasts/contractWithDeepGenerics.kt");
}
@Test
@TestMetadata("contractsOnMembers.kt")
public void testContractsOnMembers() throws Exception {
@@ -34044,6 +34121,23 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/evaluate")
@TestDataPath("$PROJECT_ROOT")
@Execution(ExecutionMode.SAME_THREAD)
public class Evaluate {
@Test
public void testAllFilesPresentInEvaluate() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/evaluate"), Pattern.compile("^(.+)\\.kt$"), Pattern.compile("^(.+)\\.fir\\.kts?$"), true);
}
@Test
@TestMetadata("charCodeExpType.kt")
public void testCharCodeExpType() throws Exception {
runTest("compiler/testData/diagnostics/testsWithStdLib/evaluate/charCodeExpType.kt");
}
}
@Nested
@TestMetadata("compiler/testData/diagnostics/testsWithStdLib/experimental")
@TestDataPath("$PROJECT_ROOT")
@@ -62,6 +62,7 @@ enum class PositioningStrategy(private val strategy: String? = null) {
FLOAT_LITERAL_OUT_OF_RANGE,
LONG_LITERAL_SUFFIX,
REIFIED_MODIFIER,
TYPE_PARAMETERS_LIST,
;
@@ -338,7 +338,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
val REIFIED_TYPE_PARAMETER_NO_INLINE by error<KtTypeParameter>(PositioningStrategy.REIFIED_MODIFIER)
val TYPE_PARAMETERS_NOT_ALLOWED by error<KtDeclaration>()
val TYPE_PARAMETERS_NOT_ALLOWED by error<KtDeclaration>(PositioningStrategy.TYPE_PARAMETERS_LIST)
val TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER by error<KtTypeParameter>()
@@ -349,7 +349,7 @@ object DIAGNOSTICS_LIST : DiagnosticList() {
val CYCLIC_GENERIC_UPPER_BOUND by error<PsiElement>()
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error<KtTypeParameterList>()
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error<KtDeclaration>(PositioningStrategy.TYPE_PARAMETERS_LIST)
val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning<KtTypeParameter>()
@@ -245,11 +245,11 @@ object FirErrors {
val NAME_IN_CONSTRAINT_IS_NOT_A_TYPE_PARAMETER by error2<KtSimpleNameExpression, Name, FirDeclaration>()
val BOUND_ON_TYPE_ALIAS_PARAMETER_NOT_ALLOWED by error0<KtTypeReference>()
val REIFIED_TYPE_PARAMETER_NO_INLINE by error0<KtTypeParameter>(SourceElementPositioningStrategies.REIFIED_MODIFIER)
val TYPE_PARAMETERS_NOT_ALLOWED by error0<KtDeclaration>()
val TYPE_PARAMETERS_NOT_ALLOWED by error0<KtDeclaration>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val TYPE_PARAMETER_OF_PROPERTY_NOT_USED_IN_RECEIVER by error0<KtTypeParameter>()
val RETURN_TYPE_MISMATCH by error2<KtExpression, ConeKotlinType, ConeKotlinType>(SourceElementPositioningStrategies.WHOLE_ELEMENT)
val CYCLIC_GENERIC_UPPER_BOUND by error0<PsiElement>()
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error0<KtTypeParameterList>()
val DEPRECATED_TYPE_PARAMETER_SYNTAX by error0<KtDeclaration>(SourceElementPositioningStrategies.TYPE_PARAMETERS_LIST)
val MISPLACED_TYPE_PARAMETER_CONSTRAINTS by warning0<KtTypeParameter>()
val DYNAMIC_UPPER_BOUND by error0<KtTypeReference>()
@@ -21,7 +21,7 @@ object FirFunctionTypeParametersChecker : FirSimpleFunctionChecker() {
val nameNode = source.treeStructure.nameIdentifier(source.lighterASTNode)
if (typeParamsNode != null && nameNode != null && typeParamsNode.startOffset > nameNode.startOffset) {
reporter.reportOn(
typeParamsNode.toFirLightSourceElement(source.treeStructure),
source,
FirErrors.DEPRECATED_TYPE_PARAMETER_SYNTAX,
context
)
@@ -35,9 +35,9 @@ object FirAnonymousFunctionChecker : FirExpressionChecker<FirStatement>() {
context: CheckerContext
) {
val source = expression.source ?: return
source.treeStructure.typeParametersList(source.lighterASTNode)?.let { typeParamsNode ->
source.treeStructure.typeParametersList(source.lighterASTNode)?.let { _ ->
reporter.reportOn(
typeParamsNode.toFirLightSourceElement(source.treeStructure),
source,
FirErrors.TYPE_PARAMETERS_NOT_ALLOWED,
context
)
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.lexer.KtTokens
import org.jetbrains.kotlin.lexer.KtTokens.MODALITY_MODIFIERS
import org.jetbrains.kotlin.lexer.KtTokens.VISIBILITY_MODIFIERS
import org.jetbrains.kotlin.psi.KtParameter.VAL_VAR_TOKEN_SET
import org.jetbrains.kotlin.psi.psiUtil.endOffset
import org.jetbrains.kotlin.psi.stubs.elements.KtConstantExpressionElementType
import org.jetbrains.kotlin.utils.addToStdlib.firstNotNullResult
@@ -267,7 +268,7 @@ object LightTreePositioningStrategies {
endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode>
): List<TextRange> {
val value = tree.lastChild(node) ?: node
val value = node.nonFillerLastChildOrSelf(tree)
return markElement(value, startOffset, endOffset, tree, node)
}
}
@@ -573,10 +574,32 @@ object LightTreePositioningStrategies {
val WHOLE_ELEMENT = object : LightTreePositioningStrategy() { }
val LONG_LITERAL_SUFFIX = object : LightTreePositioningStrategy() {
override fun mark(
node: LighterASTNode,
startOffset: Int,
endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode>
): List<TextRange> {
if (node.tokenType == KtNodeTypes.INTEGER_CONSTANT) {
return listOf(TextRange.create(endOffset - 1, endOffset))
}
return super.mark(node, startOffset, endOffset, tree)
}
}
val REIFIED_MODIFIER: LightTreePositioningStrategy =
ModifierSetBasedLightTreePositioningStrategy(TokenSet.create(KtTokens.REIFIED_KEYWORD))
val TYPE_PARAMETERS_LIST: LightTreePositioningStrategy = object : LightTreePositioningStrategy() {
override fun mark(
node: LighterASTNode,
startOffset: Int,
endOffset: Int,
tree: FlyweightCapableTreeStructure<LighterASTNode>
): List<TextRange> {
return markElement(tree.typeParametersList(node) ?: node, startOffset, endOffset, tree, node)
}
}
}
fun FirSourceElement.hasValOrVar(): Boolean =
@@ -809,7 +832,7 @@ private fun FlyweightCapableTreeStructure<LighterASTNode>.firstChild(node: Light
}
private fun FlyweightCapableTreeStructure<LighterASTNode>.lastChild(node: LighterASTNode): LighterASTNode? {
val childrenRef = Ref<Array<LighterASTNode>>()
val childrenRef = Ref<Array<LighterASTNode?>>()
getChildren(node, childrenRef)
return childrenRef.get().lastOrNull()
return childrenRef.get().lastOrNull { it != null }
}
@@ -69,7 +69,7 @@ private val FILLER_TOKENS = setOf(
private fun LighterASTNode.nonFillerFirstChildOrSelf(tree: FlyweightCapableTreeStructure<LighterASTNode>): LighterASTNode =
getChildren(tree).firstOrNull { it != null && it.tokenType !in FILLER_TOKENS } ?: this
private fun LighterASTNode.nonFillerLastChildOrSelf(tree: FlyweightCapableTreeStructure<LighterASTNode>): LighterASTNode =
internal fun LighterASTNode.nonFillerLastChildOrSelf(tree: FlyweightCapableTreeStructure<LighterASTNode>): LighterASTNode =
getChildren(tree).lastOrNull { it != null && it.tokenType !in FILLER_TOKENS } ?: this
@@ -202,4 +202,9 @@ object SourceElementPositioningStrategies {
LightTreePositioningStrategies.REIFIED_MODIFIER,
PositioningStrategies.REIFIED_MODIFIER
)
val TYPE_PARAMETERS_LIST = SourceElementPositioningStrategy(
LightTreePositioningStrategies.TYPE_PARAMETERS_LIST,
PositioningStrategies.TYPE_PARAMETERS_LIST
)
}
@@ -671,25 +671,26 @@ class ExpressionsConverter(
usedAsExpression = whenExpression.usedAsExpression
for (entry in whenEntries) {
val branch = entry.firBlock
val entrySource = entry.node.toFirSourceElement()
branches += if (!entry.isElse) {
if (hasSubject) {
val firCondition = entry.toFirWhenCondition()
buildWhenBranch {
source = branch.source
source = entrySource
condition = firCondition
result = branch
}
} else {
val firCondition = entry.toFirWhenConditionWithoutSubject()
buildWhenBranch {
source = branch.source
source = entrySource
condition = firCondition
result = branch
}
}
} else {
buildWhenBranch {
source = branch.source
source = entrySource
condition = buildElseIfTrueCondition()
result = branch
}
@@ -721,7 +722,7 @@ class ExpressionsConverter(
}
}
return WhenEntry(conditions, firBlock, isElse)
return WhenEntry(conditions, firBlock, whenEntry, isElse)
}
private fun convertWhenConditionExpression(whenCondition: LighterASTNode, whenRefWithSubject: FirExpressionRef<FirWhenExpression>?): FirExpression {
@@ -1179,7 +1180,9 @@ class ExpressionsConverter(
*/
private fun convertReturn(returnExpression: LighterASTNode): FirExpression {
var labelName: String? = null
var firExpression: FirExpression = buildUnitExpression()
var firExpression: FirExpression = buildUnitExpression {
source = returnExpression.toFirSourceElement(FirFakeSourceElementKind.ImplicitUnit)
}
returnExpression.forEachChildren {
when (it.tokenType) {
LABEL_QUALIFIER -> labelName = it.getAsStringWithoutBacktick().replace("@", "")
@@ -5,6 +5,7 @@
package org.jetbrains.kotlin.fir.lightTree.fir
import com.intellij.lang.LighterASTNode
import org.jetbrains.kotlin.fir.builder.generateLazyLogicalOperation
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
@@ -15,6 +16,7 @@ import org.jetbrains.kotlin.fir.expressions.buildErrorExpression
data class WhenEntry(
val conditions: List<FirExpression>,
val firBlock: FirBlock,
val node: LighterASTNode,
val isElse: Boolean = false
) {
fun toFirWhenCondition(): FirExpression {
@@ -39,4 +41,4 @@ data class WhenEntry(
else -> condition
}
}
}
}
@@ -790,6 +790,15 @@ object PositioningStrategies {
val WHOLE_ELEMENT: PositioningStrategy<KtElement> = object : PositioningStrategy<KtElement>() {}
val TYPE_PARAMETERS_LIST: PositioningStrategy<KtDeclaration> = object : PositioningStrategy<KtDeclaration>() {
override fun mark(element: KtDeclaration): List<TextRange> {
if (element is KtTypeParameterListOwner) {
return markElement(element.typeParameterList ?: element)
}
return markElement(element)
}
}
/**
* @param locateReferencedName whether to remove any nested parentheses while locating the reference element. This is useful for
@@ -4,7 +4,7 @@ fun foo(@<!UNRESOLVED_REFERENCE!>varargs<!> f : Int) {}
var bar : Int = 1
set(@<!UNRESOLVED_REFERENCE!>varargs<!> v) {}
val x : (Int) -> Int = {@<!UNRESOLVED_REFERENCE!>varargs<!> x <!SYNTAX!>: Int -> x<!>}
val x : (Int) -> Int = <!INITIALIZER_TYPE_MISMATCH{LT}!>{@<!UNRESOLVED_REFERENCE!>varargs<!> x <!SYNTAX!>: Int -> x<!>}<!>
class Hello(@<!UNRESOLVED_REFERENCE!>varargs<!> args: Any) {
}
@@ -8,7 +8,7 @@ fun foo(@test f : Int) {}
var bar : Int = 1
set(@test v) {}
val x : (Int) -> Int = {@test x <!SYNTAX!>: Int -> x<!>} // todo fix parser annotation on lambda parameter
val x : (Int) -> Int = <!INITIALIZER_TYPE_MISMATCH{LT}!>{@test x <!SYNTAX!>: Int -> x<!>}<!> // todo fix parser annotation on lambda parameter
class Hello(@test args: Any) {
}