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)?Uberunix
08/06/2025, 4:05 PM:this (primary constructor paramaters)
Is there some future benefit to this method I'll uncover as I learn more? Because right now it seems unnecessarily redundant to supply the parameters from a call to the primary when they could just be sent directly to the appropriate secondary.
Or maybe I'm wrong? Maybe both primary and secondaries DO get called together, separating concerns for safety? So that vital data is always reliably built with the primary, and then added onto by the secondaries if possible?damian
08/06/2025, 8:27 PMzsmb
08/22/2025, 9:28 AM