What about adding a contract to delegated properties, which allows smartcast with the provided value by ensuring to always provide the same value?
Use case: kotlinx-cli parser or Compose State. Both libraries ensure the provided value is stable and does not change.
Copy code
val parser = ArgParser("ejwrapper")
val jobID by parser.option(ArgType.String)
parser.parse(args) // No changes to jobID after parsing
if (jobID != null) {
val status = getJobStatus(jobID) // smart cast is not possible because jobID has a open or custom getter