https://kotlinlang.org logo
Title
s

shikasd

07/08/2020, 12:42 AM
heyo, I pushed it a bit further last two evenings and got basic support for sealed classes working in this PR for now only it supports data class with one parameter, because I need to pass the info about index of parameter to IR level somehow. (Problem for tomorrow) I also had to rewrite some parts of analysis. Now we go through contents of all files and check when expressions directly instead of relying on diagnostics to detect them. And the last change, we also have a
todo
property in the prelude which serves as a placeholder to complete calls in PSI. (also merged master, so sorry for a bit messy changeset)
@mattmoore pinging you as usual 🙂
m

mattmoore

07/08/2020, 12:45 AM
Nice! I'll take a look soon 🙂
@shikasd Just updated upstream pattern-matching branch with master. Can you try rebasing on upstream pattern-matching branch?
s

shikasd

07/08/2020, 5:51 PM
thanks, just did this seems like tests got merged a bit weirdly, will fix this now
seems alright now
m

mattmoore

07/08/2020, 6:00 PM
👍
@shikasd This is really neat. I didn't know you could create your own slice with custom types:
val PATTERN_EXPRESSION = Slices.createSimpleSlice<KtWhenEntry, PatternExpression>()
val PATTERN_EXPRESSION_CAPTURED_PARAMS = Slices.createCollectiveSetSlice<KtNameReferenceExpression>()
val PATTERN_EXPRESSION_BODY_PARAMS = Slices.createCollectiveSetSlice<KtSimpleNameExpression>()
s

shikasd

07/08/2020, 6:38 PM
Yeah, I learned it from kotlinx.serialiaztion long time ago
Unfortunately, toString doesn't work well with those :)
@mattmoore Updated my PR, now all tests pass No need for a todo property anymore, I decided to create them on the fly kinda like compose does, so I could keep track of which
component
function to call Also it now supports other expressions as captured params, so test const strings work correctly as well. To achieve that, I have written a simple transform which basically converts
case(Person("Matt", "Moore"))
into
subject is Person && subject.component1() == "Matt" && subject.component2() == "Moore"
m

mattmoore

07/09/2020, 2:34 AM
This looks great! I merged your PR.
r

raulraja

07/11/2020, 2:29 PM
awesome stuff @shikasd 👏
Some of those component methods are unsafe in the std lib and would cause the pattern to blow up
like destructuring a list
that is empty. We need to ensure the desugaring is safe in those cases because a user always expect the match to be a partial function. This is why unapply in Scala returns an Option tupled
that is if any of those result in the match results on an exception by invoking componentN it needs to go towards false in the desugar in such a way that it does not blow up
ideally it detects if it’s a data class then it’s safe to not try catch
but any component1 declared in interfaces have to be safe wrapped and non fatal exceptions coerced to false or the cases won’t form partial functions.
s

shikasd

07/12/2020, 6:05 PM
For now I check if the call is constructor for class I think ideally, I would check if parameters of constructor have a corresponding property, so probably we could extend support to more than just data classes But in general, I think supporting only them is fine