generated from JavierSegoviaCordoba/kotlin-template-javiersc
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix type mismatch errors inside the
copy
function are not shown
- Loading branch information
1 parent
bb4a24c
commit c6c7a2e
Showing
10 changed files
with
437 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
|
||
### Fixed | ||
|
||
- type mismatch errors inside the `copy` function are not shown | ||
|
||
### Removed | ||
|
||
### Updated | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
...c/kotlin/kopy/compiler/fir/checker/checkers/expression/ArgumentTypeMismatchTypeChecker.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package com.javiersc.kotlin.kopy.compiler.fir.checker.checkers.expression | ||
|
||
import com.javiersc.kotlin.kopy.compiler.fir.checker.FirKopyError | ||
import com.javiersc.kotlin.kopy.compiler.fir.utils.isKopyFunctionSetCall | ||
import org.jetbrains.kotlin.diagnostics.DiagnosticReporter | ||
import org.jetbrains.kotlin.diagnostics.SourceElementPositioningStrategies | ||
import org.jetbrains.kotlin.diagnostics.reportOn | ||
import org.jetbrains.kotlin.fir.FirSession | ||
import org.jetbrains.kotlin.fir.analysis.checkers.MppCheckerKind | ||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext | ||
import org.jetbrains.kotlin.fir.analysis.checkers.expression.FirCallChecker | ||
import org.jetbrains.kotlin.fir.expressions.FirCall | ||
import org.jetbrains.kotlin.fir.expressions.FirFunctionCall | ||
import org.jetbrains.kotlin.fir.expressions.arguments | ||
import org.jetbrains.kotlin.fir.types.ConeKotlinType | ||
import org.jetbrains.kotlin.fir.types.renderReadable | ||
import org.jetbrains.kotlin.fir.types.resolvedType | ||
import org.jetbrains.kotlin.fir.types.typeContext | ||
import org.jetbrains.kotlin.types.AbstractTypeChecker | ||
|
||
internal class ArgumentTypeMismatchTypeChecker( | ||
private val session: FirSession, | ||
) : FirCallChecker(MppCheckerKind.Common) { | ||
|
||
override fun check(expression: FirCall, context: CheckerContext, reporter: DiagnosticReporter) { | ||
if (!expression.isKopyFunctionSetCall) return | ||
if (expression !is FirFunctionCall) return | ||
|
||
val extensionType: ConeKotlinType? = expression.extensionReceiver?.resolvedType | ||
val argumentType: ConeKotlinType? = expression.arguments.firstOrNull()?.resolvedType | ||
|
||
if (extensionType == null || argumentType == null) return | ||
|
||
val isSubtype: Boolean = | ||
AbstractTypeChecker.isSubtypeOf( | ||
context = session.typeContext, | ||
subType = extensionType, | ||
superType = argumentType, | ||
) | ||
if (!isSubtype) { | ||
reporter.reportOn( | ||
source = expression.arguments.first().source, | ||
factory = FirKopyError.ARGUMENT_TYPE_MISMATCH, | ||
a = extensionType.renderReadable(), | ||
b = argumentType.renderReadable(), | ||
context = context, | ||
positioningStrategy = SourceElementPositioningStrategies.DEFAULT, | ||
) | ||
} | ||
} | ||
} |
Oops, something went wrong.