https://kotlinlang.org logo
#getting-started
Title
# getting-started
e

elect

05/31/2022, 3:40 PM
has anyone found a way to force mandatory parameters in DSL other than moving them as constructor arguments?
j

Joffrey

05/31/2022, 3:42 PM
A bunch of DSLs are functions rather than constructors, so I would say function arguments as well. I don't think you can have compile errors if you use a "property assignment" approach, if that's what you're looking for. You can generate runtime errors though, but I'd honestly prefer function or constructor arguments. What do you not like about those?
Another option is to provide a reasonable default of course, but I think that's not the scope of the question
e

elect

05/31/2022, 3:53 PM
maybe with Contracts?
damn
Contracts are allowed only for functions
d

dmitriy.novozhilov

05/31/2022, 7:29 PM
It's very nice to see links to my masters degree Samples from this repo very may as example for this degree and weren't be accepted to master of kotlin in this way But I think we will revisit them in K2 compiler
e

elect

06/01/2022, 4:37 AM
@dmitriy.novozhilov is there an update on which solutions are available right now? Also with weird workarounds or additional code overhead
d

dmitriy.novozhilov

06/01/2022, 5:35 AM
No, there is nothing on compiler side But you can create a workaround on your API side: you can pass required values to arguments of builder function, and initialize in lambda only optional ones
30 Views