Status of kotlin.internal.contracts?


#1

What is the status of kotlin.internal.contracts?
Are there any plans to make this public?


Why doesn't smart cast use data from in-code contracts?
#2

Hello!

Currently, the status is “internal evaluation”. We have a prototype, which covers some basic cases, and we’re going to start testing it in our own project in the near future. We expect that after thorough testing and polishing, this basic model (with some set of pre-defined contracts) will be published. However, we can’t guarantee anything at the moment – this feature is quite large and complex, and there’s a probability that we’ll find some show-stopper, that’s why we haven’t made any announcement yet.

In the long term, there are a lot of open design questions – how powerful we would like to make this feature, should it be totally public or not, which use cases it should cover and which shouldn’t, etc. When we will be sure about basic support of kotlin.internal.contracts, we’ll definitely post some KEEP to discuss this in public.

Hope that cleared some confusion about this feature!


#3

I noticed these contracts in a few places, what exactly are they?


#4

This is an experimental mechanism purpose of which is to provide compiler with an additional information about functions’ behavior, which can help analysis quality. In particular, this could help with cases like this, which are currently not working:

if (!x.isNullOrEmpty()) { 
  // we know that 'x != null' here 
  println(x.length)
}

#5

THAT WOULD BE SO AWESOME!!! This seems like it could go very far!!! Very cool!!!