Hi
@Oliver Eisenbarth The current version of refined types would be able to do that because the refinement and compile time evaluations happens over Companion invoke calls that are detached from the class instances themselves but we are removing that plugin in favor of Arrow-Analysis. Arrow-Analysis is currently in active development by
@Alejandro Serrano Mena and myself and we have an ETA for first release by Dec 2021. This plugin can perform more complex data flow analysis and ensure code is safer even when you don’t use your own refined types. For a glimpse at what it can do you can check out the tests in this file
https://github.com/arrow-kt/arrow-meta/blob/main/plugins/analysis/kotlin-plugin/src/test/kotlin/arrow/meta/plugins/analysis/AnalysisTests.kt
Arrow-Analysis uses an smt solver and lifts the kotlin expressions ensuring pre, post and invariants are obeyed across the program dataflow. It report call sites and places that would otherwise not pass the requirements and provides information as to why.
I originally developed the Refined types support as a prototype of what could be done with the Ir constant expression evaluator in the compiler. Finally when
@Alejandro Serrano Mena joined me in this problem he convinced me there was a better way to do all this so we are abandoning the old refinements in favor of this plugin. In the test file you can find examples like
PostiveInt
, collection access and others that show outcomes of compilation with and without the plugin applied