Effects: add DSL for declaration of contracts
- Introduce DSL for declaration of contracts. Functions and classes in this DSL do not bear any computational semantics: in fact, they all do not exist on runtime. Whole work of extracting semantics from such calls is done by special parts of compiler - To make distinguishing those declarations more robust and convenient, introduce internal annotation @ContractsDSL - Turn off InlineChecker inside contracts DSL. We do this, because some functions from DSL should take any possible lambda, so we can't write any type besides 'Function<R>'. However, InlineChecker will complain if we will pass inlined lambda in such function -- though, this is false positive because we know that functions from contracts DSL will never be executed - Change testData on HierarchyTestWithLib, where new enum from kotlin.internal changed expected output ========== Effect System introduction: 7/18
This commit is contained in:
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.config.LanguageFeature
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.diagnostics.Errors
|
||||
import org.jetbrains.kotlin.diagnostics.Errors.*
|
||||
import org.jetbrains.kotlin.contracts.parsing.isFromContractDsl
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
import org.jetbrains.kotlin.psi.*
|
||||
import org.jetbrains.kotlin.psi.psiUtil.getParentOfType
|
||||
@@ -59,10 +60,15 @@ internal class InlineChecker(private val descriptor: FunctionDescriptor) : CallC
|
||||
|
||||
override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) {
|
||||
val expression = resolvedCall.call.calleeExpression ?: return
|
||||
|
||||
supportDefaultValueInline = context.languageVersionSettings.supportsFeature(LanguageFeature.InlineDefaultFunctionalParameters)
|
||||
|
||||
//checking that only invoke or inlinable extension called on function parameter
|
||||
val targetDescriptor = resolvedCall.resultingDescriptor
|
||||
|
||||
// Omit inline checks for 'contract'-call because those calls will never be executed, so inline checking is pointless
|
||||
if (targetDescriptor.isFromContractDsl()) return
|
||||
|
||||
checkCallWithReceiver(context, targetDescriptor, resolvedCall.dispatchReceiver, expression)
|
||||
checkCallWithReceiver(context, targetDescriptor, resolvedCall.extensionReceiver, expression)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user