@@ -3,6 +3,7 @@ package dev.mokkery.plugin.fir.diagnostics
33import dev.mokkery.plugin.Mokkery.Callable
44import dev.mokkery.plugin.fir.acceptsMatcher
55import dev.mokkery.plugin.fir.allNonDispatchArgumentsMapping
6+ import dev.mokkery.plugin.fir.compat.isSimpleFunctionCompat
67import dev.mokkery.plugin.fir.extractArrayLiteralCall
78import dev.mokkery.plugin.fir.isSpread
89import org.jetbrains.kotlin.config.CompilerConfiguration
@@ -20,7 +21,7 @@ import org.jetbrains.kotlin.fir.declarations.FirClass
2021import org.jetbrains.kotlin.fir.declarations.FirFunction
2122import org.jetbrains.kotlin.fir.declarations.FirProperty
2223import org.jetbrains.kotlin.fir.declarations.FirRegularClass
23- import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction
24+ import org.jetbrains.kotlin.fir.declarations.FirNamedFunction
2425import org.jetbrains.kotlin.fir.declarations.utils.isFinal
2526import org.jetbrains.kotlin.fir.expressions.FirBooleanOperatorExpression
2627import org.jetbrains.kotlin.fir.expressions.FirDoWhileLoop
@@ -86,11 +87,15 @@ class MatchersUsageReporterVisitor(
8687 private val callAssociatedLambdas = mutableMapOf<FirFunctionSymbol <* >, FirFunctionCall ? > ()
8788 private val legalizedNonMemberFunctionWithMatchers = mutableSetOf<FirFunctionCall >()
8889
89- override fun visitElement (element : FirElement ) = element.acceptChildren(this )
90+ override fun visitElement (element : FirElement ) {
91+ // backward compat - cannot override removed type so it's handled here
92+ if (element is FirFunction && element.isSimpleFunctionCompat()) return visitFunction(element)
93+ element.acceptChildren(this )
94+ }
9095
9196 override fun visitAnonymousObject (anonymousObject : FirAnonymousObject ) {
9297 nestedClassStack.add(anonymousObject.symbol)
93- super .visitAnonymousObject(anonymousObject )
98+ anonymousObject.acceptChildren( this )
9499 nestedClassStack.popLast()
95100 }
96101
@@ -100,40 +105,40 @@ class MatchersUsageReporterVisitor(
100105
101106 override fun visitClass (klass : FirClass ) {
102107 nestedClassStack.add(klass.symbol)
103- super .visitClass(klass )
108+ klass.acceptChildren( this )
104109 nestedClassStack.popLast()
105110 }
106111
107112 override fun visitAnonymousFunction (anonymousFunction : FirAnonymousFunction ) {
108113 functionsStack + = anonymousFunction.symbol
109114 callAssociatedLambdas[anonymousFunction.symbol] = currentCallsStack.lastOrNull()
110- super .visitAnonymousFunction(anonymousFunction )
115+ anonymousFunction.acceptChildren( this )
111116 callAssociatedLambdas.remove(anonymousFunction.symbol)
112117 functionsStack - = anonymousFunction.symbol
113118 }
114119
115- override fun visitSimpleFunction ( simpleFunction : FirSimpleFunction ) {
116- visitFunction(simpleFunction )
120+ override fun visitNamedFunction ( namedFunction : FirNamedFunction ) {
121+ visitFunction(namedFunction )
117122 }
118123
119124 override fun visitFunction (function : FirFunction ) {
120125 functionsStack + = function.symbol
121- super .visitFunction(function )
126+ function.acceptChildren( this )
122127 functionsStack - = function.symbol
123128 }
124129
125130 override fun visitProperty (property : FirProperty ) {
126131 matchersProcessor.processVariable(property)
127- super .visitProperty(property )
132+ property.acceptChildren( this )
128133 }
129134
130135 override fun visitVariableAssignment (variableAssignment : FirVariableAssignment ) = context(context) {
131136 val variableSymbol = variableAssignment
132137 .calleeReference
133138 ?.toResolvedVariableSymbol()
134- ? : return @context super .visitVariableAssignment(variableAssignment )
135- if (variableAssignment.dispatchReceiver != null ) return @context super .visitVariableAssignment(variableAssignment )
136- if (! matchersProcessor.isMatcher(variableAssignment.rValue)) return @context super .visitVariableAssignment(variableAssignment )
139+ ? : return @context variableAssignment.acceptChildren( this )
140+ if (variableAssignment.dispatchReceiver != null ) return @context variableAssignment.acceptChildren( this )
141+ if (! matchersProcessor.isMatcher(variableAssignment.rValue)) return @context variableAssignment.acceptChildren( this )
137142 when (matchersProcessor.getResultFor(variableSymbol)) {
138143 null -> reporter.reportOn(
139144 source = variableAssignment.source,
@@ -147,7 +152,7 @@ class MatchersUsageReporterVisitor(
147152 )
148153 else -> Unit
149154 }
150- return @context super .visitVariableAssignment(variableAssignment )
155+ return @context variableAssignment.acceptChildren( this )
151156 }
152157
153158 override fun visitWhenExpression (whenExpression : FirWhenExpression ) = context(context) {
@@ -161,11 +166,12 @@ class MatchersUsageReporterVisitor(
161166 .forEachMatcher {
162167 reporter.reportOn(it.source, Diagnostics .ILLEGAL_MATCHER_IN_CONDITION )
163168 }
164- super .visitWhenExpression(whenExpression )
169+ whenExpression.acceptChildren( this )
165170 }
166171
167172 override fun visitWhileLoop (whileLoop : FirWhileLoop ) {
168- visitLoop(whileLoop) }
173+ visitLoop(whileLoop)
174+ }
169175
170176 override fun visitDoWhileLoop (doWhileLoop : FirDoWhileLoop ) {
171177 visitLoop(doWhileLoop)
@@ -175,7 +181,7 @@ class MatchersUsageReporterVisitor(
175181 if (matchersProcessor.isMatcher(loop.condition)) {
176182 reporter.reportOn(loop.condition.source, Diagnostics .ILLEGAL_MATCHER_IN_CONDITION )
177183 }
178- super .visitLoop(loop )
184+ loop.acceptChildren( this )
179185 }
180186
181187 override fun visitTypeOperatorCall (typeOperatorCall : FirTypeOperatorCall ) = context(context) {
@@ -184,7 +190,7 @@ class MatchersUsageReporterVisitor(
184190 reporter.reportOn(it.source, Diagnostics .ILLEGAL_OPERATOR_USAGE , typeOperatorCall.operation.operator )
185191 }
186192 }
187- super .visitTypeOperatorCall(typeOperatorCall )
193+ typeOperatorCall.acceptChildren( this )
188194 }
189195
190196 override fun visitEqualityOperatorCall (equalityOperatorCall : FirEqualityOperatorCall ) = context(context) {
@@ -197,7 +203,7 @@ class MatchersUsageReporterVisitor(
197203 )
198204 }
199205 }
200- super .visitEqualityOperatorCall(equalityOperatorCall )
206+ equalityOperatorCall.acceptChildren( this )
201207 }
202208
203209 override fun visitBooleanOperatorExpression (
@@ -208,7 +214,7 @@ class MatchersUsageReporterVisitor(
208214 reporter.reportOn(it.source, Diagnostics .ILLEGAL_OPERATOR_USAGE , booleanOperatorExpression.kind.token)
209215 }
210216 }
211- super .visitBooleanOperatorExpression(booleanOperatorExpression )
217+ booleanOperatorExpression.acceptChildren( this )
212218 }
213219
214220 override fun visitTryExpression (tryExpression : FirTryExpression ) = context(context) {
@@ -223,24 +229,24 @@ class MatchersUsageReporterVisitor(
223229 if (matchersProcessor.isMatcher(tryExpression.finallyBlock?.lastExpression)) {
224230 reporter.reportOn(tryExpression.source, Diagnostics .ILLEGAL_TRY_CATCH )
225231 }
226- super .visitTryExpression(tryExpression )
232+ tryExpression.acceptChildren( this )
227233 }
228234
229235 override fun visitGetClassCall (getClassCall : FirGetClassCall ) = context(context) {
230236 if (matchersProcessor.isMatcher(getClassCall.argument)) {
231237 reporter.reportOn(getClassCall.argument.source, Diagnostics .ILLEGAL_OPERATOR_USAGE , " ::class" )
232238 }
233- super .visitGetClassCall(getClassCall )
239+ getClassCall.acceptChildren( this )
234240 }
235241
236242 override fun visitFunctionCall (functionCall : FirFunctionCall ): Unit = context(context) {
237243 val callee = functionCall.calleeReference as ? FirResolvedNamedReference
238- ? : return super .visitFunctionCall(functionCall )
244+ ? : return functionCall.acceptChildren( this )
239245 val symbol = callee.resolvedSymbol as ? FirFunctionSymbol <* >
240- ? : return super .visitFunctionCall(functionCall )
246+ ? : return functionCall.acceptChildren( this )
241247 if (symbol.callableId in templatingFunctions) {
242248 reporter.reportOn(functionCall.source, Diagnostics .ILLEGAL_NESTED_TEMPLATING , symbol.name)
243- return super .visitFunctionCall(functionCall )
249+ return functionCall.acceptChildren( this )
244250 }
245251 val dispatchReceiver = functionCall.dispatchReceiver
246252 when {
@@ -258,7 +264,7 @@ class MatchersUsageReporterVisitor(
258264 }
259265 }
260266 currentCallsStack.add(functionCall)
261- super .visitFunctionCall(functionCall )
267+ functionCall.acceptChildren( this )
262268 currentCallsStack.removeLast()
263269 }
264270
0 commit comments