Add expression functions with context boundaries

This commit is contained in:
pavel 2026-08-27 23:05:49 +02:00
commit 773c34f3f4
18 changed files with 391 additions and 52 deletions

View file

@ -1034,7 +1034,14 @@ func renderFunctionSignature(fn lang.FunctionDecl) string {
if len(fn.TypeParams) > 0 {
name += "<" + strings.Join(fn.TypeParams, ", ") + ">"
}
return renderFunctionSignatureFromParts(name, fn.Params, fn.ReturnType)
returnType := fn.ReturnType
if fn.InferReturn && fn.ExpressionBody != nil {
resolved := lang.ResolvedType(fn.ExpressionBody)
if resolved.String() != "<unknown>" {
returnType = resolved.String()
}
}
return renderFunctionSignatureFromParts(name, fn.Params, returnType)
}
func renderFunctionSignatureFromParts(name string, fnParams []lang.Param, returnType string) string {
@ -1640,6 +1647,7 @@ var builtinDetails = map[string]string{
"set": "fun set(target: Any, value: Any): Unit",
"now": "fun now(): time.Time",
"runBlocking": "fun runBlocking(block: () -> Unit): Unit",
"withContext": "fun withContext(ctx: context.Context, block: () -> Unit): Unit",
"coroutineScope": "contextual fun coroutineScope(block: () -> Unit): Unit",
"launch": "contextual fun launch(block: () -> Unit): Unit",
"async": "contextual fun async<T>(block: () -> T): Deferred<T>",