hhariri
elaborate tissue
12/18/2017, 10:59 AMwakingrufus
06/14/2019, 10:30 PMwakingrufus
06/14/2019, 10:31 PMirus
06/15/2019, 8:08 AMwakingrufus
06/15/2019, 2:29 PMwakingrufus
06/15/2019, 2:29 PMhhariri
wakingrufus
06/16/2019, 7:50 PMBuzz
08/27/2019, 11:45 PMVictor Cardona
02/06/2020, 2:39 AMVladyslav Sitalo
06/27/2020, 6:23 PMVictor Cardona
04/10/2021, 8:18 PMvanniktech
11/11/2021, 5:25 PMMendess
01/09/2023, 11:32 AMJoshua Hansen
09/13/2023, 8:05 PMIdo Flax
08/01/2024, 1:04 PMthis
is T
if it returns true
@OptIn(ExperimentalContracts::class)
inline infix fun <reified T : PsiElement> PsiElement.matches(pattern: PsiElementPattern.Capture<T>): Boolean {
contract { returns(true) implies (this@matches is T) }
return pattern.accepts(this)
}
the contract doesn’t work if calling it using infix syntax:
nono
inline fun <reified T : PsiElement, Y> PsiElement.doIfMatches(
pattern: PsiElementPattern.Capture<T>,
block: (T) -> Y
): Y? =
if (this matches pattern) { // <-- infix call
block(this) // <-- "[TYPE_MISMATCH] Type mismatch. Required: T Found: PsiElement"
} else {
null
}
This works
nod
inline fun <reified T : PsiElement, Y> PsiElement.doIfMatches(
pattern: PsiElementPattern.Capture<T>,
block: (T) -> Y
): Y? =
if (this.matches(pattern)) { // <-- none infix call
block(this) // <-- "Smart cast to T (for null call)" (appears twice for some reason)
} else {
null
}
Any idea what’s going on here? is this an issue with contracts (being experimental and all)?