Status of kotlin.internal.contracts?

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

2 Likes

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!

4 Likes

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

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)
}
4 Likes

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

Really looking forward to this feature, even if it just starts off as adding incremental changes to require it can improve code quality by a lot, and will add even more unique value to kotlin as a language.