FIR: suppress VARIABLE_EXPECTED for error reference
This commit is contained in:
committed by
TeamCityServer
parent
c572bf05b5
commit
a297ee66d4
+8
-3
@@ -495,8 +495,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
// following `!!` is safe since `operatorIsSuccessful = true` implies `operatorCallReference != null`
|
||||
val operatorReturnTypeMatches = operatorIsSuccessful && operatorReturnTypeMatches(operatorCallReference!!.candidate)
|
||||
|
||||
val lhsReference = leftArgument.toResolvedCallableReference()
|
||||
val lhsSymbol = lhsReference?.resolvedSymbol as? FirVariableSymbol<*>
|
||||
val lhsReference = leftArgument.toReference()
|
||||
val lhsSymbol = (lhsReference as? FirResolvedNamedReference)?.resolvedSymbol as? FirVariableSymbol<*>
|
||||
val lhsVariable = lhsSymbol?.fir
|
||||
val lhsIsVar = lhsVariable?.isVar == true
|
||||
|
||||
@@ -528,7 +528,12 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
leftArgument.calleeReference.source
|
||||
else -> leftArgument.source
|
||||
}
|
||||
diagnostic = if (lhsSymbol == null) ConeVariableExpectedError else ConeValReassignmentError(lhsSymbol)
|
||||
diagnostic = when {
|
||||
// Use a stub diagnostic to suppress unresolved error here because it would be reported by other logic
|
||||
lhsReference is FirErrorNamedReference -> ConeStubDiagnostic(ConeUnresolvedReferenceError())
|
||||
lhsSymbol == null -> ConeVariableExpectedError
|
||||
else -> ConeValReassignmentError(lhsSymbol)
|
||||
}
|
||||
}
|
||||
}
|
||||
(leftArgument as? FirQualifiedAccess)?.let {
|
||||
|
||||
@@ -56,8 +56,12 @@ inline val FirCall.argumentMapping: LinkedHashMap<FirExpression, FirValueParamet
|
||||
}
|
||||
|
||||
fun FirExpression.toResolvedCallableReference(): FirResolvedNamedReference? {
|
||||
return toReference() as? FirResolvedNamedReference
|
||||
}
|
||||
|
||||
fun FirExpression.toReference(): FirReference? {
|
||||
if (this is FirWrappedArgumentExpression) return expression.toResolvedCallableReference()
|
||||
return (this as? FirResolvable)?.calleeReference as? FirResolvedNamedReference
|
||||
return (this as? FirResolvable)?.calleeReference
|
||||
}
|
||||
|
||||
fun FirExpression.toResolvedCallableSymbol(): FirCallableSymbol<*>? {
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ fun bar1(x: Number, y: Int) {
|
||||
}
|
||||
|
||||
fun bar2(x: Number) {
|
||||
<!UNRESOLVED_REFERENCE, VARIABLE_EXPECTED!>y<!> += x as Int
|
||||
<!UNRESOLVED_REFERENCE!>y<!> += x as Int
|
||||
checkSubtype<Int>(x)
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ fun sum(a : IntArray) : Int {
|
||||
// Write your solution here
|
||||
<!UNRESOLVED_REFERENCE!>res<!> = 0
|
||||
for (e in a)
|
||||
<!UNRESOLVED_REFERENCE, VARIABLE_EXPECTED!>res<!> +=<!SYNTAX!><!>
|
||||
<!UNRESOLVED_REFERENCE!>res<!> +=<!SYNTAX!><!>
|
||||
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY{LT}!>}<!>
|
||||
fun main() {
|
||||
test(0)
|
||||
|
||||
@@ -35,11 +35,11 @@ fun test() {
|
||||
|
||||
bar {
|
||||
<!DSL_SCOPE_VIOLATION!>a<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION, VARIABLE_EXPECTED!>a<!> += <!DSL_SCOPE_VIOLATION!>a<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION!>a<!> += <!DSL_SCOPE_VIOLATION!>a<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION, DSL_SCOPE_VIOLATION!>a<!>++
|
||||
|
||||
<!DSL_SCOPE_VIOLATION!>a1<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION, VARIABLE_EXPECTED!>a1<!> += <!DSL_SCOPE_VIOLATION!>a1<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION!>a1<!> += <!DSL_SCOPE_VIOLATION!>a1<!> + 1
|
||||
<!DSL_SCOPE_VIOLATION, DSL_SCOPE_VIOLATION!>a1<!>++
|
||||
|
||||
this@foo.a + 1
|
||||
|
||||
Reference in New Issue
Block a user