Replace some FIR syntax errors with more proper diagnostics
This commit is contained in:
+1
-1
@@ -7,7 +7,7 @@ class B: A() {
|
||||
<!UNRESOLVED_REFERENCE!>invoke<!>()
|
||||
|
||||
<!SUPER_IS_NOT_AN_EXPRESSION!>super<!> {
|
||||
println('weird')
|
||||
println(<!ILLEGAL_CONST_EXPRESSION!>'weird'<!>)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ class Foo {
|
||||
|
||||
fun test() {
|
||||
var f = Foo()
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>f += f<!>
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY!>f += f<!>
|
||||
}
|
||||
+4
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.declarations.FirConstructor
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirMemberDeclaration
|
||||
|
||||
@@ -15,4 +16,7 @@ object DeclarationCheckers {
|
||||
val MEMBER_DECLARATIONS: List<FirDeclarationChecker<FirMemberDeclaration>> = DECLARATIONS + listOf(
|
||||
FirInfixFunctionDeclarationChecker
|
||||
)
|
||||
val CONSTRUCTORS: List<FirDeclarationChecker<FirConstructor>> = MEMBER_DECLARATIONS + listOf(
|
||||
FirConstructorChecker
|
||||
)
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/*
|
||||
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import org.jetbrains.kotlin.KtNodeTypes
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
|
||||
object FirConstructorChecker : FirDeclarationChecker<FirConstructor>() {
|
||||
override fun check(declaration: FirConstructor, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
val containingClass = context.containingDeclarations.lastOrNull() as? FirClass<*> ?: return
|
||||
val source = declaration.source
|
||||
val elementType = source?.elementType
|
||||
if (elementType != KtNodeTypes.PRIMARY_CONSTRUCTOR && elementType != KtNodeTypes.SECONDARY_CONSTRUCTOR) {
|
||||
return
|
||||
}
|
||||
when (containingClass.classKind) {
|
||||
ClassKind.OBJECT -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT)
|
||||
ClassKind.INTERFACE -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_INTERFACE)
|
||||
ClassKind.ENUM_ENTRY -> reporter.report(source, FirErrors.CONSTRUCTOR_IN_OBJECT)
|
||||
ClassKind.ENUM_CLASS -> if (declaration.visibility != Visibilities.PRIVATE) {
|
||||
reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM)
|
||||
}
|
||||
ClassKind.CLASS -> if (containingClass is FirRegularClass && containingClass.modality == Modality.SEALED &&
|
||||
declaration.visibility != Visibilities.PRIVATE
|
||||
) {
|
||||
reporter.report(source, FirErrors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED)
|
||||
}
|
||||
ClassKind.ANNOTATION_CLASS -> {
|
||||
// DO NOTHING
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private inline fun <reified T : FirSourceElement, P : PsiElement> DiagnosticReporter.report(
|
||||
source: T?,
|
||||
factory: FirDiagnosticFactory0<T, P>
|
||||
) {
|
||||
source?.let { report(factory.on(it)) }
|
||||
}
|
||||
}
|
||||
+34
-3
@@ -12,6 +12,10 @@ import org.jetbrains.kotlin.fir.analysis.collectors.components.*
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBreakExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirContinueExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorLoop
|
||||
import org.jetbrains.kotlin.fir.expressions.FirLoopJump
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.SessionHolder
|
||||
import org.jetbrains.kotlin.fir.resolve.collectImplicitReceivers
|
||||
@@ -66,11 +70,38 @@ abstract class AbstractDiagnosticCollector(
|
||||
element.acceptChildren(this)
|
||||
}
|
||||
|
||||
override fun visitRegularClass(regularClass: FirRegularClass) {
|
||||
private fun visitJump(loopJump: FirLoopJump) {
|
||||
loopJump.runComponents()
|
||||
loopJump.acceptChildren(this)
|
||||
loopJump.target.labeledElement.takeIf { it is FirErrorLoop }?.accept(this)
|
||||
}
|
||||
|
||||
override fun visitBreakExpression(breakExpression: FirBreakExpression) {
|
||||
visitJump(breakExpression)
|
||||
}
|
||||
|
||||
override fun visitContinueExpression(continueExpression: FirContinueExpression) {
|
||||
visitJump(continueExpression)
|
||||
}
|
||||
|
||||
private fun visitClassAndChildren(klass: FirClass<*>, type: ConeKotlinType) {
|
||||
val typeRef = buildResolvedTypeRef {
|
||||
type = regularClass.defaultType()
|
||||
this.type = type
|
||||
}
|
||||
visitWithDeclarationAndReceiver(regularClass, regularClass.name, typeRef)
|
||||
visitWithDeclarationAndReceiver(klass, (klass as? FirRegularClass)?.name, typeRef)
|
||||
|
||||
}
|
||||
|
||||
override fun visitRegularClass(regularClass: FirRegularClass) {
|
||||
visitClassAndChildren(regularClass, regularClass.defaultType())
|
||||
}
|
||||
|
||||
override fun visitSealedClass(sealedClass: FirSealedClass) {
|
||||
visitClassAndChildren(sealedClass, sealedClass.defaultType())
|
||||
}
|
||||
|
||||
override fun visitAnonymousObject(anonymousObject: FirAnonymousObject) {
|
||||
visitClassAndChildren(anonymousObject, anonymousObject.defaultType())
|
||||
}
|
||||
|
||||
override fun visitSimpleFunction(simpleFunction: FirSimpleFunction) {
|
||||
|
||||
+1
-1
@@ -34,7 +34,7 @@ class DeclarationCheckersDiagnosticComponent(collector: AbstractDiagnosticCollec
|
||||
}
|
||||
|
||||
override fun visitConstructor(constructor: FirConstructor, data: CheckerContext) {
|
||||
runCheck { DeclarationCheckers.MEMBER_DECLARATIONS.check(constructor, data, it) }
|
||||
runCheck { DeclarationCheckers.CONSTRUCTORS.check(constructor, data, it) }
|
||||
}
|
||||
|
||||
override fun visitAnonymousFunction(anonymousFunction: FirAnonymousFunction, data: CheckerContext) {
|
||||
|
||||
+20
-19
@@ -12,10 +12,8 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory0
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.FirErrorFunction
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind
|
||||
import org.jetbrains.kotlin.fir.diagnostics.*
|
||||
import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorLoop
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
@@ -68,21 +66,24 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect
|
||||
private fun ConeSimpleDiagnostic.getFactory(): FirDiagnosticFactory0<FirSourceElement, *> {
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return when (kind) {
|
||||
DiagnosticKind.Syntax -> FirErrors.SYNTAX_ERROR
|
||||
DiagnosticKind.ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED
|
||||
DiagnosticKind.UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL
|
||||
DiagnosticKind.IllegalConstExpression -> FirErrors.ILLEGAL_CONST_EXPRESSION
|
||||
DiagnosticKind.ConstructorInObject -> FirErrors.CONSTRUCTOR_IN_OBJECT
|
||||
DiagnosticKind.DeserializationError -> FirErrors.DESERIALIZATION_ERROR
|
||||
DiagnosticKind.InferenceError -> FirErrors.INFERENCE_ERROR
|
||||
DiagnosticKind.NoSupertype -> FirErrors.NO_SUPERTYPE
|
||||
DiagnosticKind.TypeParameterAsSupertype -> FirErrors.TYPE_PARAMETER_AS_SUPERTYPE
|
||||
DiagnosticKind.EnumAsSupertype -> FirErrors.ENUM_AS_SUPERTYPE
|
||||
DiagnosticKind.RecursionInSupertypes -> FirErrors.RECURSION_IN_SUPERTYPES
|
||||
DiagnosticKind.RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES
|
||||
DiagnosticKind.SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION
|
||||
DiagnosticKind.Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION
|
||||
DiagnosticKind.Other -> FirErrors.OTHER_ERROR
|
||||
Syntax -> FirErrors.SYNTAX_ERROR
|
||||
ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED
|
||||
UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL
|
||||
IllegalConstExpression -> FirErrors.ILLEGAL_CONST_EXPRESSION
|
||||
DeserializationError -> FirErrors.DESERIALIZATION_ERROR
|
||||
InferenceError -> FirErrors.INFERENCE_ERROR
|
||||
NoSupertype -> FirErrors.NO_SUPERTYPE
|
||||
TypeParameterAsSupertype -> FirErrors.TYPE_PARAMETER_AS_SUPERTYPE
|
||||
EnumAsSupertype -> FirErrors.ENUM_AS_SUPERTYPE
|
||||
RecursionInSupertypes -> FirErrors.RECURSION_IN_SUPERTYPES
|
||||
RecursionInImplicitTypes -> FirErrors.RECURSION_IN_IMPLICIT_TYPES
|
||||
SuperNotAllowed -> FirErrors.SUPER_IS_NOT_AN_EXPRESSION
|
||||
Java -> FirErrors.ERROR_FROM_JAVA_RESOLUTION
|
||||
ExpressionRequired -> FirErrors.EXPRESSION_REQUIRED
|
||||
JumpOutsideLoop -> FirErrors.BREAK_OR_CONTINUE_OUTSIDE_A_LOOP
|
||||
NotLoopLabel -> FirErrors.NOT_A_LOOP_LABEL
|
||||
VariableExpected -> FirErrors.VARIABLE_EXPECTED
|
||||
Other -> FirErrors.OTHER_ERROR
|
||||
else -> throw IllegalArgumentException("Unsupported diagnostic kind: $kind at $javaClass")
|
||||
}
|
||||
}
|
||||
|
||||
+10
-4
@@ -29,6 +29,9 @@ object FirErrors {
|
||||
val RECURSION_IN_SUPERTYPES by error0<FirSourceElement, PsiElement>()
|
||||
val RECURSION_IN_IMPLICIT_TYPES by error0<FirSourceElement, PsiElement>()
|
||||
val ERROR_FROM_JAVA_RESOLUTION by error0<FirSourceElement, PsiElement>()
|
||||
val EXPRESSION_REQUIRED by error0<FirSourceElement, PsiElement>()
|
||||
val BREAK_OR_CONTINUE_OUTSIDE_A_LOOP by error0<FirSourceElement, PsiElement>()
|
||||
val NOT_A_LOOP_LABEL by error0<FirSourceElement, PsiElement>()
|
||||
val OTHER_ERROR by error0<FirSourceElement, PsiElement>()
|
||||
val TYPE_MISMATCH by error2<FirSourceElement, PsiElement, ConeKotlinType, ConeKotlinType>()
|
||||
val VARIABLE_EXPECTED by error0<FirSourceElement, PsiElement>()
|
||||
@@ -37,9 +40,12 @@ object FirErrors {
|
||||
|
||||
val INAPPLICABLE_INFIX_MODIFIER by existing<FirSourceElement, PsiElement, String>(Errors.INAPPLICABLE_INFIX_MODIFIER)
|
||||
val CONSTRUCTOR_IN_OBJECT by existing<FirSourceElement, KtDeclaration>(Errors.CONSTRUCTOR_IN_OBJECT)
|
||||
val CONSTRUCTOR_IN_INTERFACE by existing<FirSourceElement, KtDeclaration>(Errors.CONSTRUCTOR_IN_INTERFACE)
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_ENUM by existing<FirSourceElement, PsiElement>(Errors.NON_PRIVATE_CONSTRUCTOR_IN_ENUM)
|
||||
val NON_PRIVATE_CONSTRUCTOR_IN_SEALED by existing<FirSourceElement, PsiElement>(Errors.NON_PRIVATE_CONSTRUCTOR_IN_SEALED)
|
||||
|
||||
val REPEATED_MODIFIER by error1<FirSourceElement, KtModifierKeywordToken>()
|
||||
val REDUNDANT_MODIFIER by error2<FirSourceElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
val DEPRECATED_MODIFIER_PAIR by error2<FirSourceElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
val INCOMPATIBLE_MODIFIERS by error2<FirSourceElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
val REPEATED_MODIFIER by error1<FirSourceElement, PsiElement, KtModifierKeywordToken>()
|
||||
val REDUNDANT_MODIFIER by error2<FirSourceElement, PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
val DEPRECATED_MODIFIER_PAIR by error2<FirSourceElement, PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
val INCOMPATIBLE_MODIFIERS by error2<FirSourceElement, PsiElement, KtModifierKeywordToken, KtModifierKeywordToken>()
|
||||
}
|
||||
|
||||
+40
-34
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.builder
|
||||
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.tree.IElementType
|
||||
import org.jetbrains.kotlin.KtNodeTypes.*
|
||||
import org.jetbrains.kotlin.descriptors.Modality
|
||||
@@ -36,7 +35,6 @@ import org.jetbrains.kotlin.lexer.KtTokens.OPEN_QUOTE
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import org.jetbrains.kotlin.psi.KtStringTemplateExpression
|
||||
import org.jetbrains.kotlin.psi.KtUnaryExpression
|
||||
import org.jetbrains.kotlin.resolve.constants.evaluate.*
|
||||
import org.jetbrains.kotlin.util.OperatorNameConventions
|
||||
@@ -57,6 +55,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
abstract fun T.getReferencedNameAsName(): Name
|
||||
abstract fun T.getLabelName(): String?
|
||||
abstract fun T.getExpressionInParentheses(): T?
|
||||
abstract fun T.getAnnotatedExpression(): T?
|
||||
abstract fun T.getChildNodeByType(type: IElementType): T?
|
||||
abstract val T?.selectorExpression: T?
|
||||
|
||||
@@ -173,12 +172,13 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
fun FirLoopJumpBuilder.bindLabel(expression: T): FirLoopJumpBuilder {
|
||||
val labelName = expression.getLabelName()
|
||||
val lastLoopTarget = context.firLoopTargets.lastOrNull()
|
||||
val sourceElement = expression.toFirSourceElement()
|
||||
if (labelName == null) {
|
||||
target = lastLoopTarget ?: FirLoopTarget(labelName).apply {
|
||||
bind(
|
||||
buildErrorLoop(
|
||||
expression.getSourceOrNull(),
|
||||
ConeSimpleDiagnostic("Cannot bind unlabeled jump to a loop", DiagnosticKind.Syntax)
|
||||
sourceElement,
|
||||
ConeSimpleDiagnostic("Cannot bind unlabeled jump to a loop", DiagnosticKind.JumpOutsideLoop)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -192,7 +192,11 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
target = FirLoopTarget(labelName).apply {
|
||||
bind(
|
||||
buildErrorLoop(
|
||||
expression.getSourceOrNull(), ConeSimpleDiagnostic("Cannot bind label $labelName to a loop", DiagnosticKind.Syntax)
|
||||
sourceElement,
|
||||
ConeSimpleDiagnostic(
|
||||
"Cannot bind label $labelName to a loop",
|
||||
lastLoopTarget?.let { DiagnosticKind.NotLoopLabel } ?: DiagnosticKind.JumpOutsideLoop
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -200,14 +204,10 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
return this
|
||||
}
|
||||
|
||||
/**** Conversion utils ****/
|
||||
private fun <T> T.getSourceOrNull(): FirSourceElement? {
|
||||
return if (this is PsiElement) FirPsiSourceElement(this) else null
|
||||
}
|
||||
|
||||
fun generateConstantExpressionByLiteral(expression: T): FirExpression {
|
||||
val type = expression.elementType
|
||||
val text: String = expression.asText
|
||||
val sourceElement = expression.toFirSourceElement()
|
||||
val convertedText: Any? = when (type) {
|
||||
INTEGER_CONSTANT, FLOAT_CONSTANT -> parseNumericLiteral(text, type)
|
||||
BOOLEAN_CONSTANT -> parseBoolean(text)
|
||||
@@ -217,7 +217,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
INTEGER_CONSTANT -> {
|
||||
val kind = when {
|
||||
convertedText !is Long -> return buildErrorExpression {
|
||||
source = expression.getSourceOrNull()
|
||||
source = sourceElement
|
||||
diagnostic = ConeSimpleDiagnostic(
|
||||
"Incorrect constant expression: $text",
|
||||
DiagnosticKind.IllegalConstExpression
|
||||
@@ -240,44 +240,44 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
}
|
||||
|
||||
buildConstOrErrorExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
kind,
|
||||
convertedText,
|
||||
ConeSimpleDiagnostic("Incorrect integer literal: $text", DiagnosticKind.Syntax)
|
||||
ConeSimpleDiagnostic("Incorrect integer literal: $text", DiagnosticKind.IllegalConstExpression)
|
||||
)
|
||||
}
|
||||
FLOAT_CONSTANT ->
|
||||
if (convertedText is Float) {
|
||||
buildConstOrErrorExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
FirConstKind.Float,
|
||||
convertedText,
|
||||
ConeSimpleDiagnostic("Incorrect float: $text", DiagnosticKind.Syntax)
|
||||
ConeSimpleDiagnostic("Incorrect float: $text", DiagnosticKind.IllegalConstExpression)
|
||||
)
|
||||
} else {
|
||||
buildConstOrErrorExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
FirConstKind.Double,
|
||||
convertedText as Double,
|
||||
ConeSimpleDiagnostic("Incorrect double: $text", DiagnosticKind.Syntax)
|
||||
ConeSimpleDiagnostic("Incorrect double: $text", DiagnosticKind.IllegalConstExpression)
|
||||
)
|
||||
}
|
||||
CHARACTER_CONSTANT ->
|
||||
buildConstOrErrorExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
FirConstKind.Char,
|
||||
text.parseCharacter(),
|
||||
ConeSimpleDiagnostic("Incorrect character: $text", DiagnosticKind.Syntax)
|
||||
ConeSimpleDiagnostic("Incorrect character: $text", DiagnosticKind.IllegalConstExpression)
|
||||
)
|
||||
BOOLEAN_CONSTANT ->
|
||||
buildConstExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
FirConstKind.Boolean,
|
||||
convertedText as Boolean
|
||||
)
|
||||
NULL ->
|
||||
buildConstExpression(
|
||||
expression.getSourceOrNull(),
|
||||
sourceElement,
|
||||
FirConstKind.Null,
|
||||
null
|
||||
)
|
||||
@@ -287,7 +287,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
}
|
||||
|
||||
fun Array<out T?>.toInterpolatingCall(
|
||||
base: KtStringTemplateExpression?,
|
||||
base: T,
|
||||
convertTemplateEntry: T?.(String) -> FirExpression
|
||||
): FirExpression {
|
||||
return buildStringConcatenationCall {
|
||||
@@ -300,11 +300,11 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
OPEN_QUOTE, CLOSING_QUOTE -> continue@L
|
||||
LITERAL_STRING_TEMPLATE_ENTRY -> {
|
||||
sb.append(entry.asText)
|
||||
buildConstExpression(entry.getSourceOrNull(), FirConstKind.String, entry.asText)
|
||||
buildConstExpression(entry.toFirSourceElement(), FirConstKind.String, entry.asText)
|
||||
}
|
||||
ESCAPE_STRING_TEMPLATE_ENTRY -> {
|
||||
sb.append(entry.unescapedValue)
|
||||
buildConstExpression(entry.getSourceOrNull(), FirConstKind.String, entry.unescapedValue)
|
||||
buildConstExpression(entry.toFirSourceElement(), FirConstKind.String, entry.unescapedValue)
|
||||
}
|
||||
SHORT_STRING_TEMPLATE_ENTRY, LONG_STRING_TEMPLATE_ENTRY -> {
|
||||
hasExpressions = true
|
||||
@@ -322,7 +322,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
else -> {
|
||||
hasExpressions = true
|
||||
buildErrorExpression {
|
||||
source = entry.getSourceOrNull()
|
||||
source = entry.toFirSourceElement()
|
||||
diagnostic = ConeSimpleDiagnostic("Incorrect template entry: ${entry.asText}", DiagnosticKind.Syntax)
|
||||
}
|
||||
}
|
||||
@@ -361,7 +361,8 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
|
||||
// TODO: Refactor, support receiver capturing in case of a.b
|
||||
fun generateIncrementOrDecrementBlock(
|
||||
baseExpression: KtUnaryExpression?,
|
||||
baseExpression: T,
|
||||
operationReference: T?,
|
||||
argument: T?,
|
||||
callName: Name,
|
||||
prefix: Boolean,
|
||||
@@ -383,7 +384,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
val resultInitializer = buildFunctionCall {
|
||||
source = baseSource
|
||||
calleeReference = buildSimpleNamedReference {
|
||||
source = baseExpression?.operationReference?.toFirSourceElement()
|
||||
source = operationReference?.toFirSourceElement()
|
||||
name = callName
|
||||
}
|
||||
explicitReceiver = generateResolvedAccessExpression(source, temporaryVariable)
|
||||
@@ -432,13 +433,13 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
when (tokenType) {
|
||||
REFERENCE_EXPRESSION -> {
|
||||
return buildSimpleNamedReference {
|
||||
source = left.getSourceOrNull()
|
||||
source = left.toFirSourceElement()
|
||||
name = left.getReferencedNameAsName()
|
||||
}
|
||||
}
|
||||
THIS_EXPRESSION -> {
|
||||
return buildExplicitThisReference {
|
||||
source = left.getSourceOrNull()
|
||||
source = left.toFirSourceElement()
|
||||
labelName = left.getLabelName()
|
||||
}
|
||||
}
|
||||
@@ -450,7 +451,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
firMemberAccess.calleeReference
|
||||
} else {
|
||||
buildErrorNamedReference {
|
||||
source = left.getSourceOrNull()
|
||||
source = left.toFirSourceElement()
|
||||
diagnostic = ConeSimpleDiagnostic("Unsupported qualified LValue: ${left.asText}", DiagnosticKind.Syntax)
|
||||
}
|
||||
}
|
||||
@@ -458,11 +459,14 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
PARENTHESIZED -> {
|
||||
return initializeLValue(left.getExpressionInParentheses(), convertQualified)
|
||||
}
|
||||
ANNOTATED_EXPRESSION -> {
|
||||
return initializeLValue(left.getAnnotatedExpression(), convertQualified)
|
||||
}
|
||||
}
|
||||
}
|
||||
return buildErrorNamedReference {
|
||||
source = left.getSourceOrNull()
|
||||
diagnostic = ConeSimpleDiagnostic("Unsupported LValue: $tokenType", DiagnosticKind.Syntax)
|
||||
source = left?.toFirSourceElement()
|
||||
diagnostic = ConeSimpleDiagnostic("Unsupported LValue: $tokenType", DiagnosticKind.VariableExpected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +501,9 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
argumentList = buildBinaryArgumentList(
|
||||
this@generateAssignment?.convert() ?: buildErrorExpression {
|
||||
source = null
|
||||
diagnostic = ConeSimpleDiagnostic("Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.Syntax)
|
||||
diagnostic = ConeSimpleDiagnostic(
|
||||
"Unsupported left value of assignment: ${baseSource?.psi?.text}", DiagnosticKind.ExpressionRequired
|
||||
)
|
||||
},
|
||||
value
|
||||
)
|
||||
@@ -678,7 +684,7 @@ abstract class BaseFirBuilder<T>(val baseSession: FirSession, val context: Conte
|
||||
|
||||
fun List<Pair<T, FirProperty>>.generateCopyFunction(
|
||||
session: FirSession,
|
||||
classOrObject: KtClassOrObject?,
|
||||
classOrObject: T,
|
||||
classBuilder: AbstractFirRegularClassBuilder,
|
||||
packageFqName: FqName,
|
||||
classFqName: FqName,
|
||||
|
||||
+8
@@ -71,6 +71,14 @@ open class BaseConverter(
|
||||
return null
|
||||
}
|
||||
|
||||
override fun LighterASTNode.getAnnotatedExpression(): LighterASTNode? {
|
||||
this.forEachChildren {
|
||||
if (it.isExpression()) return it
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
override fun LighterASTNode.getChildNodeByType(type: IElementType): LighterASTNode? {
|
||||
return this.getChildNodesByType(type).firstOrNull()
|
||||
}
|
||||
|
||||
+3
-19
@@ -462,7 +462,7 @@ class DeclarationsConverter(
|
||||
baseSession, this, context.packageFqName, context.className, firPrimaryConstructor
|
||||
)
|
||||
zippedParameters.generateCopyFunction(
|
||||
baseSession, null, this, context.packageFqName, context.className, firPrimaryConstructor
|
||||
baseSession, classNode, this, context.packageFqName, context.className, firPrimaryConstructor
|
||||
)
|
||||
// TODO: equals, hashCode, toString
|
||||
}
|
||||
@@ -718,15 +718,7 @@ class DeclarationsConverter(
|
||||
}
|
||||
}
|
||||
|
||||
val delegatedSelfTypeRef =
|
||||
if (classWrapper.isObjectLiteral()) buildErrorTypeRef {
|
||||
source = secondaryConstructor.toFirSourceElement()
|
||||
diagnostic = ConeSimpleDiagnostic(
|
||||
"Constructor in object",
|
||||
DiagnosticKind.ConstructorInObject
|
||||
)
|
||||
}
|
||||
else classWrapper.delegatedSelfTypeRef
|
||||
val delegatedSelfTypeRef = classWrapper.delegatedSelfTypeRef
|
||||
|
||||
val explicitVisibility = modifiers.getVisibility()
|
||||
val status = FirDeclarationStatusImpl(explicitVisibility, Modality.FINAL).apply {
|
||||
@@ -777,15 +769,7 @@ class DeclarationsConverter(
|
||||
val isImplicit = constructorDelegationCall.asText.isEmpty()
|
||||
val isThis = (isImplicit && classWrapper.hasPrimaryConstructor) || thisKeywordPresent
|
||||
val delegatedType =
|
||||
if (classWrapper.isObjectLiteral() || classWrapper.isInterface()) when {
|
||||
isThis -> buildErrorTypeRef {
|
||||
diagnostic = ConeSimpleDiagnostic("Constructor in object", DiagnosticKind.ConstructorInObject)
|
||||
}
|
||||
else -> buildErrorTypeRef {
|
||||
diagnostic = ConeSimpleDiagnostic("No super type", DiagnosticKind.Syntax)
|
||||
}
|
||||
}
|
||||
else when {
|
||||
when {
|
||||
isThis -> classWrapper.delegatedSelfTypeRef
|
||||
else -> classWrapper.delegatedSuperTypeRef
|
||||
}
|
||||
|
||||
+16
-6
@@ -55,7 +55,11 @@ class ExpressionsConverter(
|
||||
) : BaseConverter(session, tree, offset, context) {
|
||||
|
||||
inline fun <reified R : FirElement> getAsFirExpression(expression: LighterASTNode?, errorReason: String = ""): R {
|
||||
return expression?.let { convertExpression(it, errorReason) } as? R ?: (buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax)) as R)
|
||||
return expression?.let {
|
||||
convertExpression(it, errorReason)
|
||||
} as? R ?: buildErrorExpression(
|
||||
null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired)
|
||||
) as R
|
||||
}
|
||||
|
||||
/***** EXPRESSIONS *****/
|
||||
@@ -103,7 +107,7 @@ class ExpressionsConverter(
|
||||
|
||||
OBJECT_LITERAL -> declarationsConverter.convertObjectLiteral(expression)
|
||||
FUN -> declarationsConverter.convertFunctionDeclaration(expression)
|
||||
else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax))
|
||||
else -> buildErrorExpression(null, ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,9 +314,13 @@ class ExpressionsConverter(
|
||||
private fun convertUnaryExpression(unaryExpression: LighterASTNode): FirExpression {
|
||||
lateinit var operationTokenName: String
|
||||
var argument: LighterASTNode? = null
|
||||
var operationReference: LighterASTNode? = null
|
||||
unaryExpression.forEachChildren {
|
||||
when (it.tokenType) {
|
||||
OPERATION_REFERENCE -> operationTokenName = it.asText
|
||||
OPERATION_REFERENCE -> {
|
||||
operationReference = it
|
||||
operationTokenName = it.asText
|
||||
}
|
||||
else -> if (it.isExpression()) argument = it
|
||||
}
|
||||
}
|
||||
@@ -330,7 +338,8 @@ class ExpressionsConverter(
|
||||
conventionCallName != null -> {
|
||||
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
|
||||
return generateIncrementOrDecrementBlock(
|
||||
null,
|
||||
unaryExpression,
|
||||
operationReference,
|
||||
argument,
|
||||
callName = conventionCallName,
|
||||
prefix = unaryExpression.tokenType == PREFIX_EXPRESSION
|
||||
@@ -548,7 +557,7 @@ class ExpressionsConverter(
|
||||
* @see org.jetbrains.kotlin.parsing.KotlinExpressionParsing.parseStringTemplate
|
||||
*/
|
||||
private fun convertStringTemplate(stringTemplate: LighterASTNode): FirExpression {
|
||||
return stringTemplate.getChildrenAsArray().toInterpolatingCall(null) { convertShortOrLongStringTemplate(it) }
|
||||
return stringTemplate.getChildrenAsArray().toInterpolatingCall(stringTemplate) { convertShortOrLongStringTemplate(it) }
|
||||
}
|
||||
|
||||
private fun LighterASTNode?.convertShortOrLongStringTemplate(errorReason: String): FirExpression {
|
||||
@@ -1053,8 +1062,9 @@ class ExpressionsConverter(
|
||||
}
|
||||
|
||||
val jumpBuilder = if (isBreak) FirBreakExpressionBuilder() else FirContinueExpressionBuilder()
|
||||
val sourceElement = jump.toFirSourceElement()
|
||||
return jumpBuilder.apply {
|
||||
source = jump.toFirSourceElement()
|
||||
source = sourceElement
|
||||
}.bindLabel(jump).build()
|
||||
}
|
||||
|
||||
|
||||
+23
-21
@@ -82,6 +82,10 @@ class RawFirBuilder(
|
||||
return (this as KtParenthesizedExpression).expression
|
||||
}
|
||||
|
||||
override fun PsiElement.getAnnotatedExpression(): PsiElement? {
|
||||
return (this as KtAnnotatedExpression).baseExpression
|
||||
}
|
||||
|
||||
override val PsiElement?.selectorExpression: PsiElement?
|
||||
get() = (this as? KtQualifiedExpression)?.selectorExpression
|
||||
|
||||
@@ -135,14 +139,14 @@ class RawFirBuilder(
|
||||
if (stubMode) buildExpressionStub()
|
||||
else with(this()) {
|
||||
convertSafe() ?: buildErrorExpression(
|
||||
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax),
|
||||
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired),
|
||||
)
|
||||
}
|
||||
|
||||
private fun KtExpression?.toFirExpression(errorReason: String): FirExpression =
|
||||
if (stubMode) buildExpressionStub()
|
||||
else convertSafe() ?: buildErrorExpression(
|
||||
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.Syntax),
|
||||
this?.toFirSourceElement(), ConeSimpleDiagnostic(errorReason, DiagnosticKind.ExpressionRequired),
|
||||
)
|
||||
|
||||
private fun KtExpression.toFirStatement(errorReason: String): FirStatement =
|
||||
@@ -152,16 +156,13 @@ class RawFirBuilder(
|
||||
convert()
|
||||
|
||||
private fun KtDeclaration.toFirDeclaration(
|
||||
delegatedSuperType: FirTypeRef?, delegatedSelfType: FirResolvedTypeRef?, owner: KtClassOrObject, hasPrimaryConstructor: Boolean,
|
||||
delegatedSuperType: FirTypeRef, delegatedSelfType: FirResolvedTypeRef, owner: KtClassOrObject, hasPrimaryConstructor: Boolean,
|
||||
): FirDeclaration {
|
||||
return when (this) {
|
||||
is KtSecondaryConstructor -> {
|
||||
toFirConstructor(
|
||||
delegatedSuperType,
|
||||
delegatedSelfType ?: buildErrorTypeRef {
|
||||
source = this@toFirDeclaration.toFirSourceElement()
|
||||
diagnostic = ConeSimpleDiagnostic("Constructor in object", DiagnosticKind.ConstructorInObject)
|
||||
},
|
||||
delegatedSelfType,
|
||||
owner,
|
||||
hasPrimaryConstructor,
|
||||
)
|
||||
@@ -172,7 +173,7 @@ class RawFirBuilder(
|
||||
primaryConstructor?.valueParameters?.isEmpty() ?: owner.secondaryConstructors.let { constructors ->
|
||||
constructors.isEmpty() || constructors.any { it.valueParameters.isEmpty() }
|
||||
}
|
||||
toFirEnumEntry(delegatedSelfType!!, ownerClassHasDefaultConstructor)
|
||||
toFirEnumEntry(delegatedSelfType, ownerClassHasDefaultConstructor)
|
||||
}
|
||||
else -> convert()
|
||||
}
|
||||
@@ -397,7 +398,7 @@ class RawFirBuilder(
|
||||
delegatedSelfTypeRef: FirTypeRef?,
|
||||
delegatedEnumSuperTypeRef: FirTypeRef?,
|
||||
classKind: ClassKind,
|
||||
): FirTypeRef? {
|
||||
): FirTypeRef {
|
||||
var superTypeCallEntry: KtSuperTypeCallEntry? = null
|
||||
var delegatedSuperTypeRef: FirTypeRef? = null
|
||||
for (superTypeListEntry in superTypeListEntries) {
|
||||
@@ -452,7 +453,7 @@ class RawFirBuilder(
|
||||
if (container.superTypeRefs.isEmpty()) {
|
||||
container.superTypeRefs += defaultDelegatedSuperTypeRef
|
||||
}
|
||||
if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef
|
||||
if (this is KtClass && this.isInterface()) return delegatedSuperTypeRef ?: implicitAnyType
|
||||
|
||||
// TODO: in case we have no primary constructor,
|
||||
// it may be not possible to determine delegated super type right here
|
||||
@@ -687,13 +688,13 @@ class RawFirBuilder(
|
||||
symbol = FirAnonymousObjectSymbol()
|
||||
val delegatedSelfType = objectDeclaration.toDelegatedSelfType(this)
|
||||
objectDeclaration.extractAnnotationsTo(this)
|
||||
objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType, null, ClassKind.CLASS)
|
||||
val delegatedSuperType = objectDeclaration.extractSuperTypeListEntriesTo(this, delegatedSelfType, null, ClassKind.CLASS)
|
||||
typeRef = delegatedSelfType
|
||||
|
||||
for (declaration in objectDeclaration.declarations) {
|
||||
declarations += declaration.toFirDeclaration(
|
||||
delegatedSuperType = null,
|
||||
delegatedSelfType = null,
|
||||
delegatedSuperType,
|
||||
delegatedSelfType,
|
||||
owner = objectDeclaration,
|
||||
hasPrimaryConstructor = false,
|
||||
)
|
||||
@@ -866,7 +867,7 @@ class RawFirBuilder(
|
||||
}
|
||||
|
||||
private fun KtSecondaryConstructor.toFirConstructor(
|
||||
delegatedSuperTypeRef: FirTypeRef?,
|
||||
delegatedSuperTypeRef: FirTypeRef,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
owner: KtClassOrObject,
|
||||
hasPrimaryConstructor: Boolean,
|
||||
@@ -885,7 +886,11 @@ class RawFirBuilder(
|
||||
isFromEnumClass = owner.hasModifier(ENUM_KEYWORD)
|
||||
}
|
||||
symbol = FirConstructorSymbol(callableIdForClassConstructor())
|
||||
delegatedConstructor = getDelegationCall().convert(delegatedSuperTypeRef, delegatedSelfTypeRef, hasPrimaryConstructor)
|
||||
delegatedConstructor = getDelegationCall().convert(
|
||||
delegatedSuperTypeRef,
|
||||
delegatedSelfTypeRef,
|
||||
hasPrimaryConstructor
|
||||
)
|
||||
this@RawFirBuilder.context.firFunctionTargets += target
|
||||
extractAnnotationsTo(this)
|
||||
typeParameters += typeParametersFromSelfType(delegatedSelfTypeRef)
|
||||
@@ -898,7 +903,7 @@ class RawFirBuilder(
|
||||
}
|
||||
|
||||
private fun KtConstructorDelegationCall.convert(
|
||||
delegatedSuperTypeRef: FirTypeRef?,
|
||||
delegatedSuperTypeRef: FirTypeRef,
|
||||
delegatedSelfTypeRef: FirTypeRef,
|
||||
hasPrimaryConstructor: Boolean,
|
||||
): FirDelegatedConstructorCall {
|
||||
@@ -906,10 +911,7 @@ class RawFirBuilder(
|
||||
val source = this.toFirSourceElement()
|
||||
val delegatedType = when {
|
||||
isThis -> delegatedSelfTypeRef
|
||||
else -> delegatedSuperTypeRef ?: buildErrorTypeRef {
|
||||
this.source = source
|
||||
diagnostic = ConeSimpleDiagnostic("No super type", DiagnosticKind.Syntax)
|
||||
}
|
||||
else -> delegatedSuperTypeRef
|
||||
}
|
||||
return buildDelegatedConstructorCall {
|
||||
this.source = source
|
||||
@@ -1449,7 +1451,7 @@ class RawFirBuilder(
|
||||
conventionCallName != null -> {
|
||||
if (operationToken in OperatorConventions.INCREMENT_OPERATIONS) {
|
||||
return generateIncrementOrDecrementBlock(
|
||||
expression, argument,
|
||||
expression, expression.operationReference, argument,
|
||||
callName = conventionCallName,
|
||||
prefix = expression is KtPrefixExpression,
|
||||
) { (this as KtExpression).toFirExpression("Incorrect expression inside inc/dec") }
|
||||
|
||||
+2
-2
@@ -45,8 +45,8 @@ FILE: constructorInObject.kt
|
||||
|
||||
}
|
||||
public? final? val anonObject: <implicit> = object : R|kotlin/Any| {
|
||||
public? constructor(): <ERROR TYPE REF: Constructor in object> {
|
||||
super<<ERROR TYPE REF: No super type>>()
|
||||
public? constructor(): R|anonymous| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
@@ -10,6 +10,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.builder.FirExpressionBuilder
|
||||
|
||||
+1
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.builder.FirAnnotationContainerBuilder
|
||||
import org.jetbrains.kotlin.fir.builder.FirBuilderDsl
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorLoop
|
||||
|
||||
+2
-1
@@ -7,6 +7,7 @@ package org.jetbrains.kotlin.fir.expressions.impl
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorExpression
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
@@ -22,7 +23,7 @@ internal class FirErrorExpressionImpl(
|
||||
override val source: FirSourceElement?,
|
||||
override val diagnostic: ConeDiagnostic,
|
||||
) : FirErrorExpression() {
|
||||
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, diagnostic)
|
||||
override var typeRef: FirTypeRef = FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic))
|
||||
override val annotations: List<FirAnnotationCall> get() = emptyList()
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.fir.expressions.impl
|
||||
import org.jetbrains.kotlin.fir.FirLabel
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic
|
||||
import org.jetbrains.kotlin.fir.diagnostics.ConeStubDiagnostic
|
||||
import org.jetbrains.kotlin.fir.expressions.FirAnnotationCall
|
||||
import org.jetbrains.kotlin.fir.expressions.FirBlock
|
||||
import org.jetbrains.kotlin.fir.expressions.FirErrorLoop
|
||||
@@ -27,7 +28,7 @@ internal class FirErrorLoopImpl(
|
||||
override val diagnostic: ConeDiagnostic,
|
||||
) : FirErrorLoop() {
|
||||
override var block: FirBlock = FirEmptyExpressionBlock()
|
||||
override var condition: FirExpression = FirErrorExpressionImpl(source, diagnostic)
|
||||
override var condition: FirExpression = FirErrorExpressionImpl(source, ConeStubDiagnostic(diagnostic))
|
||||
|
||||
override fun <R, D> acceptChildren(visitor: FirVisitor<R, D>, data: D) {
|
||||
annotations.forEach { it.accept(visitor, data) }
|
||||
|
||||
@@ -9,10 +9,14 @@ class ConeSimpleDiagnostic(override val reason: String, val kind: DiagnosticKind
|
||||
|
||||
enum class DiagnosticKind {
|
||||
Syntax,
|
||||
ExpressionRequired,
|
||||
NotLoopLabel,
|
||||
JumpOutsideLoop,
|
||||
VariableExpected,
|
||||
|
||||
ReturnNotAllowed,
|
||||
UnresolvedLabel,
|
||||
IllegalConstExpression,
|
||||
ConstructorInObject,
|
||||
DeserializationError,
|
||||
InferenceError,
|
||||
NoSupertype,
|
||||
|
||||
+4
-4
@@ -139,8 +139,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
|
||||
impl(errorLoop) {
|
||||
default("block", "FirEmptyExpressionBlock()")
|
||||
default("condition", "FirErrorExpressionImpl(source, diagnostic)")
|
||||
useTypes(emptyExpressionBlock)
|
||||
default("condition", "FirErrorExpressionImpl(source, ConeStubDiagnostic(diagnostic))")
|
||||
useTypes(emptyExpressionBlock, coneStubDiagnosticType)
|
||||
}
|
||||
|
||||
impl(expression, "FirExpressionStub") {
|
||||
@@ -390,8 +390,8 @@ object ImplementationConfigurator : AbstractFirTreeImplementationConfigurator()
|
||||
|
||||
impl(errorExpression) {
|
||||
defaultEmptyList("annotations")
|
||||
default("typeRef", "FirErrorTypeRefImpl(source, diagnostic)")
|
||||
useTypes(errorTypeRefImpl)
|
||||
default("typeRef", "FirErrorTypeRefImpl(source, ConeStubDiagnostic(diagnostic))")
|
||||
useTypes(errorTypeRefImpl, coneStubDiagnosticType)
|
||||
}
|
||||
|
||||
impl(resolvedFunctionTypeRef) {
|
||||
|
||||
@@ -65,6 +65,7 @@ val pureAbstractElementType = generatedType("FirPureAbstractElement")
|
||||
val effectDeclarationType = type("fir.contracts.description", "ConeEffectDeclaration")
|
||||
val emptyContractDescriptionType = generatedType("contracts.impl", "FirEmptyContractDescription")
|
||||
val coneDiagnosticType = generatedType("diagnostics", "ConeDiagnostic")
|
||||
val coneStubDiagnosticType = generatedType("diagnostics", "ConeStubDiagnostic")
|
||||
|
||||
val dslBuilderAnnotationType = generatedType("builder", "FirBuilderDsl")
|
||||
val firImplementationDetailType = generatedType("FirImplementationDetail")
|
||||
@@ -1,4 +1,3 @@
|
||||
// IGNORE_BACKEND_FIR: JVM_IR
|
||||
@Target(AnnotationTarget.EXPRESSION)
|
||||
@Retention(AnnotationRetention.SOURCE)
|
||||
annotation class Annotation
|
||||
|
||||
+11
-11
@@ -3,26 +3,26 @@ class C {
|
||||
fun f (a : Boolean, b : Boolean) {
|
||||
b@ while (true)
|
||||
a@ {
|
||||
break@f
|
||||
<!NOT_A_LOOP_LABEL!>break@f<!>
|
||||
break
|
||||
break@b
|
||||
break@a
|
||||
<!NOT_A_LOOP_LABEL!>break@a<!>
|
||||
}
|
||||
|
||||
continue
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>
|
||||
|
||||
b@ while (true)
|
||||
a@ {
|
||||
continue@f
|
||||
<!NOT_A_LOOP_LABEL!>continue@f<!>
|
||||
continue
|
||||
continue@b
|
||||
continue@a
|
||||
<!NOT_A_LOOP_LABEL!>continue@a<!>
|
||||
}
|
||||
|
||||
break
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>
|
||||
|
||||
continue@f
|
||||
break@f
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@f<!>
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@f<!>
|
||||
}
|
||||
|
||||
fun containsBreak(a: String?, b: String?) {
|
||||
@@ -50,7 +50,7 @@ class C {
|
||||
|
||||
fun containsIllegalBreak(a: String?) {
|
||||
loop@ while(a == null) {
|
||||
break@label
|
||||
<!NOT_A_LOOP_LABEL!>break@label<!>
|
||||
}
|
||||
a.compareTo("2")
|
||||
}
|
||||
@@ -78,7 +78,7 @@ class C {
|
||||
l@ for (el in array) {
|
||||
break
|
||||
}
|
||||
if (true) break else break@l
|
||||
if (true) break else <!NOT_A_LOOP_LABEL!>break@l<!>
|
||||
}
|
||||
a.<!INAPPLICABLE_CANDIDATE!>compareTo<!>("2")
|
||||
}
|
||||
@@ -86,7 +86,7 @@ class C {
|
||||
fun twoLabelsOnLoop() {
|
||||
label1@ label2@ for (i in 1..100) {
|
||||
if (i > 0) {
|
||||
break@label1
|
||||
<!NOT_A_LOOP_LABEL!>break@label1<!>
|
||||
}
|
||||
else {
|
||||
break@label2
|
||||
|
||||
@@ -1,92 +0,0 @@
|
||||
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
|
||||
|
||||
fun breakContinueInWhen(i: Int) {
|
||||
for (y in 0..10) {
|
||||
when(i) {
|
||||
0 -> continue
|
||||
1 -> break
|
||||
2 -> {
|
||||
for(z in 0..10) {
|
||||
break
|
||||
}
|
||||
for(w in 0..10) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun breakContinueInWhenWithWhile(i: Int, j: Int) {
|
||||
while (i > 0) {
|
||||
when (i) {
|
||||
0 -> continue
|
||||
1 -> break
|
||||
2 -> {
|
||||
while (j > 0) {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun breakContinueInWhenWithDoWhile(i: Int, j: Int) {
|
||||
do {
|
||||
when (i) {
|
||||
0 -> continue
|
||||
1 -> break
|
||||
2 -> {
|
||||
do {
|
||||
if (j == 5) break
|
||||
if (j == 10) continue
|
||||
} while (j > 0)
|
||||
}
|
||||
}
|
||||
} while (i > 0)
|
||||
}
|
||||
|
||||
fun labeledBreakContinue(i: Int) {
|
||||
outer@ for (y in 0..10) {
|
||||
when (i) {
|
||||
0 -> continue@outer
|
||||
1 -> break@outer
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun testBreakContinueInWhenInWhileCondition() {
|
||||
var i = 0
|
||||
while (
|
||||
when (i) {
|
||||
1 -> break
|
||||
2 -> continue
|
||||
else -> true
|
||||
}
|
||||
) {
|
||||
++i
|
||||
}
|
||||
}
|
||||
|
||||
fun testBreakContinueInWhenInDoWhileCondition() {
|
||||
var i = 0
|
||||
do {
|
||||
++i
|
||||
} while (
|
||||
when (i) {
|
||||
1 -> break
|
||||
2 -> continue
|
||||
else -> true
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
fun testBreakContinueInWhenInForIteratorExpression(xs: List<Any>, i: Int) {
|
||||
for (x in when (i) {
|
||||
1 -> break
|
||||
2 -> continue
|
||||
else -> xs
|
||||
}) {
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +AllowBreakAndContinueInsideWhen
|
||||
|
||||
fun breakContinueInWhen(i: Int) {
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
fun test(c : Char) {
|
||||
test('')
|
||||
test(<!ILLEGAL_CONST_EXPRESSION!>''<!>)
|
||||
test('a')
|
||||
test('aa')
|
||||
<!INAPPLICABLE_CANDIDATE!>test<!>('a)
|
||||
<!UNRESOLVED_REFERENCE!>test<!>('
|
||||
<!UNRESOLVED_REFERENCE!>test<!>(0<!SYNTAX!><!>'
|
||||
test(<!ILLEGAL_CONST_EXPRESSION!>'aa'<!>)
|
||||
<!INAPPLICABLE_CANDIDATE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>'a)<!>
|
||||
<!UNRESOLVED_REFERENCE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>'<!>
|
||||
<!UNRESOLVED_REFERENCE!>test<!>(0<!ILLEGAL_CONST_EXPRESSION!><!SYNTAX!><!>'<!>
|
||||
<!UNRESOLVED_REFERENCE!>test<!>('\n')
|
||||
<!UNRESOLVED_REFERENCE!>test<!>('\\')
|
||||
<!UNRESOLVED_REFERENCE!>test<!>(''<!SYNTAX!><!>'')
|
||||
<!UNRESOLVED_REFERENCE!>test<!>(<!ILLEGAL_CONST_EXPRESSION!>''<!><!ILLEGAL_CONST_EXPRESSION!><!SYNTAX!><!>''<!>)
|
||||
test('\'')
|
||||
test('\"')
|
||||
}
|
||||
|
||||
@@ -2,11 +2,11 @@
|
||||
// KT-451 Incorrect character literals cause assertion failures
|
||||
|
||||
fun ff() {
|
||||
val b = ''
|
||||
val c = '23'
|
||||
val d = 'a
|
||||
val e = 'ab
|
||||
val f = '\'
|
||||
val b = <!ILLEGAL_CONST_EXPRESSION!>''<!>
|
||||
val c = <!ILLEGAL_CONST_EXPRESSION!>'23'<!>
|
||||
val d = <!ILLEGAL_CONST_EXPRESSION!>'a<!>
|
||||
val e = <!ILLEGAL_CONST_EXPRESSION!>'ab<!>
|
||||
val f = <!ILLEGAL_CONST_EXPRESSION!>'\'<!>
|
||||
}
|
||||
|
||||
fun test() {
|
||||
@@ -19,19 +19,19 @@ fun test() {
|
||||
'\''
|
||||
'\\'
|
||||
'\$'
|
||||
'\x'
|
||||
'\123'
|
||||
'\ra'
|
||||
'\000'
|
||||
'\000'
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\x'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\123'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\ra'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\000'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\000'<!>
|
||||
'\u0000'
|
||||
'\u000a'
|
||||
'\u000A'
|
||||
'\u'
|
||||
'\u0'
|
||||
'\u00'
|
||||
'\u000'
|
||||
'\u000z'
|
||||
'\\u000'
|
||||
'\'
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\u'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\u0'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\u00'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\u000'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\u000z'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\\u000'<!>
|
||||
<!ILLEGAL_CONST_EXPRESSION!>'\'<!>
|
||||
}
|
||||
|
||||
+16
-16
@@ -14,7 +14,7 @@ class C() : B() {
|
||||
this.c = 34
|
||||
super.c = 3535 //repeat for 'c'
|
||||
|
||||
getInt() = 12
|
||||
<!VARIABLE_EXPECTED!>getInt()<!> = 12
|
||||
}
|
||||
|
||||
fun foo1(c: C) {
|
||||
@@ -42,27 +42,27 @@ fun cannotBe() {
|
||||
var i: Int = 5
|
||||
|
||||
<!UNRESOLVED_REFERENCE!>z<!> = 30;
|
||||
"" = "";
|
||||
foo() = Unit;
|
||||
<!VARIABLE_EXPECTED!>""<!> = "";
|
||||
<!VARIABLE_EXPECTED!>foo()<!> = Unit;
|
||||
|
||||
(i as Int) = 34
|
||||
(i is Int) = false
|
||||
A() = A()
|
||||
5 = 34
|
||||
(<!VARIABLE_EXPECTED!>i as Int<!>) = 34
|
||||
(<!VARIABLE_EXPECTED!>i is Int<!>) = false
|
||||
<!VARIABLE_EXPECTED!>A()<!> = A()
|
||||
<!VARIABLE_EXPECTED!>5<!> = 34
|
||||
}
|
||||
|
||||
fun canBe(i0: Int, j: Int) {
|
||||
var i = i0
|
||||
(label@ i) = 34
|
||||
(<!VARIABLE_EXPECTED!>label@ i<!>) = 34
|
||||
|
||||
(label@ j) = 34 //repeat for j
|
||||
(<!VARIABLE_EXPECTED!>label@ j<!>) = 34 //repeat for j
|
||||
|
||||
val a = A()
|
||||
(l@ a.a) = 3894
|
||||
(<!VARIABLE_EXPECTED!>l@ a.a<!>) = 3894
|
||||
}
|
||||
|
||||
fun canBe2(j: Int) {
|
||||
(label@ j) = 34
|
||||
(<!VARIABLE_EXPECTED!>label@ j<!>) = 34
|
||||
}
|
||||
|
||||
class A() {
|
||||
@@ -77,11 +77,11 @@ class Test() {
|
||||
<!VARIABLE_EXPECTED!>getInt()<!> += 343
|
||||
(f@ <!VARIABLE_EXPECTED!>getInt()<!>) += 343
|
||||
|
||||
1++
|
||||
(r@ 1)++
|
||||
<!VARIABLE_EXPECTED!>1<!>++
|
||||
(<!VARIABLE_EXPECTED!>r@ 1<!>)++
|
||||
|
||||
getInt()++
|
||||
(m@ getInt())++
|
||||
<!VARIABLE_EXPECTED!>getInt()<!>++
|
||||
(<!VARIABLE_EXPECTED!>m@ getInt()<!>)++
|
||||
|
||||
this<!UNRESOLVED_REFERENCE!>++<!>
|
||||
|
||||
@@ -106,7 +106,7 @@ class Test() {
|
||||
<!VARIABLE_EXPECTED!>b<!> += 34
|
||||
|
||||
a++
|
||||
(l@ a)++
|
||||
(<!VARIABLE_EXPECTED!>l@ a<!>)++
|
||||
(a)++
|
||||
}
|
||||
|
||||
|
||||
@@ -1,24 +1,24 @@
|
||||
object A1() {
|
||||
constructor(x: Int = "", y: Int) : this() {
|
||||
object A1<!CONSTRUCTOR_IN_OBJECT!>()<!> {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor(x: Int = "", y: Int)<!> : this() {
|
||||
x + y
|
||||
}
|
||||
}
|
||||
|
||||
object A2 public constructor(private val prop: Int) {
|
||||
constructor(x: Int = "", y: Int) : this(x * y) {
|
||||
object A2 public <!CONSTRUCTOR_IN_OBJECT!>constructor(private val prop: Int)<!> {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor(x: Int = "", y: Int)<!> : this(x * y) {
|
||||
x + y
|
||||
}
|
||||
}
|
||||
|
||||
val x = object (val prop: Int) {
|
||||
<!CONSTRUCTOR_IN_OBJECT, CONSTRUCTOR_IN_OBJECT!>constructor()<!> : <!UNRESOLVED_REFERENCE!>this<!>(1) {
|
||||
val x = object <!CONSTRUCTOR_IN_OBJECT!>(val prop: Int)<!> {
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!> : <!UNRESOLVED_REFERENCE!>this<!>(1) {
|
||||
val x = 1
|
||||
x * x
|
||||
}
|
||||
}
|
||||
|
||||
class A3 {
|
||||
companion object B(val prop: Int) {
|
||||
public constructor() : this(2)
|
||||
companion object B<!CONSTRUCTOR_IN_OBJECT!>(val prop: Int)<!> {
|
||||
public <!CONSTRUCTOR_IN_OBJECT!>constructor()<!> : this(2)
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ fun test(a: Any) {
|
||||
a foo"asd${a}sfsa"
|
||||
a foo"""sdf"""
|
||||
a foo'd'
|
||||
a foo''
|
||||
a foo<!ILLEGAL_CONST_EXPRESSION!>''<!>
|
||||
|
||||
a foo""foo a
|
||||
a foo"asd"foo a
|
||||
@@ -19,17 +19,17 @@ fun test(a: Any) {
|
||||
a foo"asd${a}sfsa"foo a
|
||||
a foo"""sdf"""foo a
|
||||
a foo'd'foo a
|
||||
a foo''foo a
|
||||
a foo<!ILLEGAL_CONST_EXPRESSION!>''<!>foo a
|
||||
|
||||
a in"foo"
|
||||
a in"""foo"""
|
||||
a in's'
|
||||
a in''
|
||||
a in<!ILLEGAL_CONST_EXPRESSION!>''<!>
|
||||
|
||||
a !in"foo"
|
||||
a !in"""foo"""
|
||||
a !in's'
|
||||
a !in''
|
||||
a !in<!ILLEGAL_CONST_EXPRESSION!>''<!>
|
||||
|
||||
if("s"is Any) {}
|
||||
if("s"is Any) {}
|
||||
|
||||
@@ -9,7 +9,7 @@ interface T2 constructor() {}
|
||||
interface T3 private constructor(a: Int) {}
|
||||
|
||||
interface T4 {
|
||||
constructor(a: Int) {
|
||||
<!CONSTRUCTOR_IN_INTERFACE!>constructor(a: Int)<!> {
|
||||
val b: Int = 1
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -18,4 +18,4 @@ class G {
|
||||
companion object F<T>
|
||||
}
|
||||
|
||||
object H<T, R>()
|
||||
object H<T, R><!CONSTRUCTOR_IN_OBJECT!>()<!>
|
||||
|
||||
+1
-1
@@ -9,7 +9,7 @@ annotation class Foo(
|
||||
|
||||
annotation class Bar(
|
||||
val a: Array<String> = [' '],
|
||||
val b: Array<String> = ["", ''],
|
||||
val b: Array<String> = ["", <!ILLEGAL_CONST_EXPRESSION!>''<!>],
|
||||
val c: Array<String> = [1]
|
||||
)
|
||||
|
||||
|
||||
Vendored
+7
-7
@@ -1,17 +1,17 @@
|
||||
fun test() {
|
||||
|
||||
l@ for (i in if (true) 1..10 else continue@l) {}
|
||||
for (i in if (true) 1..10 else continue) {}
|
||||
l@ for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@l<!>) {}
|
||||
for (i in if (true) 1..10 else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
|
||||
|
||||
while (break) {}
|
||||
l@ while (break@l) {}
|
||||
while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!>) {}
|
||||
l@ while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@l<!>) {}
|
||||
|
||||
do {} while (continue)
|
||||
l@ do {} while (continue@l)
|
||||
do {} while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>)
|
||||
l@ do {} while (<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue@l<!>)
|
||||
|
||||
//KT-5704
|
||||
var i = 0
|
||||
while (if(i++ == 10) break else continue) {}
|
||||
while (if(i++ == 10) <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break<!> else <!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>continue<!>) {}
|
||||
}
|
||||
|
||||
fun test2(b: Boolean) {
|
||||
|
||||
Vendored
+1
-1
@@ -1,5 +1,5 @@
|
||||
|
||||
fun foo1() = while (b()) {}
|
||||
fun foo1() = <!EXPRESSION_REQUIRED!>while (b()) {}<!>
|
||||
|
||||
fun foo2() = <!UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE, UNRESOLVED_REFERENCE!>for (i in 10) {}<!>
|
||||
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ class Test3 {
|
||||
}
|
||||
|
||||
fun test4() {
|
||||
break@test4
|
||||
<!BREAK_OR_CONTINUE_OUTSIDE_A_LOOP!>break@test4<!>
|
||||
}
|
||||
|
||||
class Test5 {
|
||||
@@ -43,11 +43,11 @@ class Test6 {
|
||||
class Test7 {
|
||||
fun Test7() {
|
||||
Test8@ while (true) {
|
||||
break@Test7
|
||||
<!NOT_A_LOOP_LABEL!>break@Test7<!>
|
||||
}
|
||||
|
||||
Test7@ while (true) {
|
||||
break@Test8
|
||||
<!NOT_A_LOOP_LABEL!>break@Test8<!>
|
||||
}
|
||||
}
|
||||
}
|
||||
compiler/testData/diagnostics/tests/controlStructures/kt770.fir.kt351.fir.kt735_StatementType.fir.kt
Vendored
+5
-5
@@ -15,7 +15,7 @@ fun main() {
|
||||
}
|
||||
|
||||
//KT-351 Distinguish statement and expression positions
|
||||
val w = while (true) {}
|
||||
val w = <!EXPRESSION_REQUIRED!>while (true) {}<!>
|
||||
|
||||
fun foo() {
|
||||
var z = 2
|
||||
@@ -152,12 +152,12 @@ fun bar(a: Unit) {}
|
||||
|
||||
fun testStatementInExpressionContext() {
|
||||
var z = 34
|
||||
val a1: Unit = z = 334
|
||||
val a1: Unit = <!EXPRESSION_REQUIRED!>z = 334<!>
|
||||
val f = for (i in 1..10) {}
|
||||
if (true) return z = 34
|
||||
return while (true) {}
|
||||
if (true) return <!EXPRESSION_REQUIRED!>z = 34<!>
|
||||
return <!EXPRESSION_REQUIRED!>while (true) {}<!>
|
||||
}
|
||||
|
||||
fun testStatementInExpressionContext2() {
|
||||
val a2: Unit = while(true) {}
|
||||
val a2: Unit = <!EXPRESSION_REQUIRED!>while(true) {}<!>
|
||||
}
|
||||
@@ -1 +1 @@
|
||||
data object Object(val x: Int, val y: Int)
|
||||
data object Object<!CONSTRUCTOR_IN_OBJECT!>(val x: Int, val y: Int)<!>
|
||||
|
||||
Vendored
+4
-4
@@ -4,7 +4,7 @@
|
||||
fun foo(block: () -> (() -> Int)) {}
|
||||
|
||||
fun test() {
|
||||
val x = fun named1(x: Int): Int { return 1 }
|
||||
val x = <!EXPRESSION_REQUIRED!>fun named1(x: Int): Int { return 1 }<!>
|
||||
x <!INAPPLICABLE_CANDIDATE!>checkType<!> { <!UNRESOLVED_REFERENCE!>_<!><Function1<Int, Int>>() }
|
||||
|
||||
foo { fun named2(): Int {return 1} }
|
||||
@@ -45,12 +45,12 @@ fun test() {
|
||||
x4 checkType { <!UNRESOLVED_REFERENCE!>_<!><Function1<Int, Unit>>() }
|
||||
|
||||
{ y: Int -> fun named14(): Int {return 1} }
|
||||
val b = <!UNRESOLVED_REFERENCE!>(fun named15(): Boolean { return true })()<!>
|
||||
val b = <!UNRESOLVED_REFERENCE!>(<!EXPRESSION_REQUIRED!>fun named15(): Boolean { return true }<!>)()<!>
|
||||
|
||||
baz(fun named16(){})
|
||||
baz(<!EXPRESSION_REQUIRED!>fun named16(){}<!>)
|
||||
}
|
||||
|
||||
fun bar() = fun named() {}
|
||||
fun bar() = <!EXPRESSION_REQUIRED!>fun named() {}<!>
|
||||
|
||||
fun <T> run(block: () -> T): T = null!!
|
||||
fun run2(block: () -> Unit): Unit = null!!
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
enum class E public constructor(val x: Int) {
|
||||
enum class E <!NON_PRIVATE_CONSTRUCTOR_IN_ENUM!>public constructor(val x: Int)<!> {
|
||||
FIRST();
|
||||
|
||||
internal constructor(): this(42)
|
||||
<!NON_PRIVATE_CONSTRUCTOR_IN_ENUM!>internal constructor(): this(42)<!>
|
||||
|
||||
constructor(y: Int, z: Int): this(y + z)
|
||||
}
|
||||
|
||||
+1
-1
@@ -5,5 +5,5 @@ fun foo() {
|
||||
fun A.foo() {}
|
||||
(fun A.foo() {})
|
||||
|
||||
run(fun foo() {})
|
||||
run(<!EXPRESSION_REQUIRED!>fun foo() {}<!>)
|
||||
}
|
||||
|
||||
@@ -6,12 +6,12 @@ fun foo(i: Int) = i
|
||||
fun bar(l: Long) = l
|
||||
|
||||
fun main() {
|
||||
val i = <!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>111111111111111777777777777777<!>
|
||||
val i = <!ILLEGAL_CONST_EXPRESSION!>111111111111111777777777777777<!>
|
||||
|
||||
//todo add diagnostic text messages
|
||||
//report only 'The value is out of range'
|
||||
//not 'An integer literal does not conform to the expected type Int/Long'
|
||||
val l: Long = <!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>1111111111111117777777777777777<!>
|
||||
foo(<!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
|
||||
bar(<!ILLEGAL_CONST_EXPRESSION, ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
|
||||
val l: Long = <!ILLEGAL_CONST_EXPRESSION!>1111111111111117777777777777777<!>
|
||||
foo(<!ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
|
||||
bar(<!ILLEGAL_CONST_EXPRESSION!>11111111111111177777777777777<!>)
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,5 +8,5 @@ operator fun RemAndRemAssign.remAssign(x: Int) {}
|
||||
|
||||
fun test() {
|
||||
var c = RemAndRemAssign
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c %= 1<!>
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY!>c %= 1<!>
|
||||
}
|
||||
+1
-1
@@ -11,7 +11,7 @@ fun test(m: MyInt) {
|
||||
m += m
|
||||
|
||||
var i = 1
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>i += 34<!>
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY!>i += 34<!>
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@ fun test() {
|
||||
val c = C()
|
||||
c += ""
|
||||
var c1 = C()
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c1 += ""<!>
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY!>c1 += ""<!>
|
||||
}
|
||||
+1
-1
@@ -15,5 +15,5 @@ fun test() {
|
||||
val c = C()
|
||||
c.c += ""
|
||||
var c1 = C1()
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY, ASSIGN_OPERATOR_AMBIGUITY!>c1.c += ""<!>
|
||||
<!ASSIGN_OPERATOR_AMBIGUITY!>c1.c += ""<!>
|
||||
}
|
||||
@@ -13,11 +13,11 @@ fun box() : Boolean {
|
||||
var c = A()
|
||||
val d = c;
|
||||
c %= A();
|
||||
return (c != d) && (c.p = "yeah")
|
||||
return (c != d) && <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!>
|
||||
}
|
||||
|
||||
|
||||
fun box2() : Boolean {
|
||||
var c = A()
|
||||
return (c.p = "yeah") && true
|
||||
return <!EXPRESSION_REQUIRED!>(c.p = "yeah")<!> && true
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
sealed class Sealed protected constructor(val x: Int) {
|
||||
sealed class Sealed <!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>protected constructor(val x: Int)<!> {
|
||||
object FIRST : Sealed()
|
||||
|
||||
public constructor(): this(42)
|
||||
<!NON_PRIVATE_CONSTRUCTOR_IN_SEALED!>public constructor(): this(42)<!>
|
||||
|
||||
constructor(y: Int, z: Int): this(y + z)
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,17 +1,17 @@
|
||||
object A {
|
||||
constructor()
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
init {}
|
||||
}
|
||||
|
||||
enum class B {
|
||||
X() {
|
||||
<!UNRESOLVED_REFERENCE!>constructor()<!>
|
||||
<!CONSTRUCTOR_IN_OBJECT, UNRESOLVED_REFERENCE!>constructor()<!>
|
||||
}
|
||||
}
|
||||
|
||||
class C {
|
||||
companion object {
|
||||
constructor()
|
||||
<!CONSTRUCTOR_IN_OBJECT!>constructor()<!>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
-3
@@ -1,3 +0,0 @@
|
||||
interface A {
|
||||
constructor()
|
||||
}
|
||||
+1
@@ -1,3 +1,4 @@
|
||||
// FIR_IDENTICAL
|
||||
interface A {
|
||||
<!CONSTRUCTOR_IN_INTERFACE!>constructor()<!>
|
||||
}
|
||||
+1
-1
@@ -4,7 +4,7 @@ fun <T : CharSequence> foo(x: Array<Any>, block: (T, Int) -> Int) {
|
||||
@Suppress("UNCHECKED_CAST") r = block(x[0] as T, "" as Int)
|
||||
|
||||
// to prevent unused assignment diagnostic for the above statement
|
||||
r.<!INAPPLICABLE_CANDIDATE!>hashCode<!>()
|
||||
r.hashCode()
|
||||
|
||||
var i = 1
|
||||
|
||||
|
||||
+1
-1
@@ -311,7 +311,7 @@ abstract class AbstractFirBaseDiagnosticsTest : BaseDiagnosticsTest() {
|
||||
|
||||
private fun Iterable<FirDiagnostic<*>>.toActualDiagnostic(root: PsiElement): List<ActualDiagnostic> {
|
||||
val result = mutableListOf<ActualDiagnostic>()
|
||||
filter { it.factory != FirErrors.SYNTAX_ERROR }.mapTo(result) {
|
||||
mapTo(result) {
|
||||
val oldDiagnostic = (it as FirPsiDiagnostic<*>).asPsiBasedDiagnostic()
|
||||
ActualDiagnostic(oldDiagnostic, null, true)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user