Add structured coroutines and explicit error handling
This commit is contained in:
parent
de1262b4cf
commit
fe62e81152
31 changed files with 1701 additions and 325 deletions
|
|
@ -998,6 +998,10 @@ func functionSemanticDiagnostics(text string, fn lang.FunctionDecl, functions ma
|
|||
}
|
||||
case lang.SelectorExpr:
|
||||
walkExpr(e.Receiver, scope)
|
||||
case lang.SafeSelectorExpr:
|
||||
walkExpr(e.Receiver, scope)
|
||||
case lang.NonNullExpr:
|
||||
walkExpr(e.Value, scope)
|
||||
case lang.IndexExpr:
|
||||
walkExpr(e.Receiver, scope)
|
||||
walkExpr(e.Index, scope)
|
||||
|
|
@ -2192,33 +2196,42 @@ func builtinHoverDetail(name string) (string, bool) {
|
|||
}
|
||||
|
||||
var builtinDetails = map[string]string{
|
||||
"println": "fun println(value: Any): Unit",
|
||||
"runCatching": "fun runCatching(block: () -> Unit): Result",
|
||||
"Channel": "fun Channel<T>(capacity: Int = 0): Channel<T>",
|
||||
"after": "fun after(ms: Int): Channel<time.Time>",
|
||||
"every": "fun every(ms: Int): Channel<time.Time>",
|
||||
"listOf": "fun listOf<T>(values: T...): List<T>",
|
||||
"mutableListOf": "fun mutableListOf<T>(values: T...): MutableList<T>",
|
||||
"mapOf": "fun mapOf<K, V>(pairs: Any...): Map<K, V>",
|
||||
"mutableMapOf": "fun mutableMapOf<K, V>(pairs: Any...): MutableMap<K, V>",
|
||||
"ByteSlice": "fun ByteSlice(value: String): ByteSlice",
|
||||
"append": "fun append<T>(values: List<T>, value: T): List<T>",
|
||||
"len": "fun len(value: Any): Int",
|
||||
"cap": "fun cap(value: Any): Int",
|
||||
"make": "fun make<T>(size: Int): T",
|
||||
"new": "fun new<T>(): *T",
|
||||
"copy": "fun copy(target: Any, source: Any): Int",
|
||||
"delete": "fun delete(map: Any, key: Any): Unit",
|
||||
"close": "fun close(channel: Any): Unit",
|
||||
"panic": "fun panic(value: Any): Unit",
|
||||
"recover": "fun recover(): Any",
|
||||
"string": "fun string(value: Any): String",
|
||||
"int": "fun int(value: Any): Int",
|
||||
"float64": "fun float64(value: Any): Double",
|
||||
"bool": "fun bool(value: Any): Boolean",
|
||||
"sql": "typed PostgreSQL query DSL",
|
||||
"set": "fun set(target: Any, value: Any): Unit",
|
||||
"now": "fun now(): time.Time",
|
||||
"println": "fun println(value: Any): Unit",
|
||||
"runCatching": "fun runCatching(block: () -> Unit): Result",
|
||||
"Channel": "fun Channel<T>(capacity: Int = 0): Channel<T>",
|
||||
"after": "fun after(ms: Int): Channel<time.Time>",
|
||||
"every": "fun every(ms: Int): Channel<time.Time>",
|
||||
"listOf": "fun listOf<T>(values: T...): List<T>",
|
||||
"mutableListOf": "fun mutableListOf<T>(values: T...): MutableList<T>",
|
||||
"mapOf": "fun mapOf<K, V>(pairs: Any...): Map<K, V>",
|
||||
"mutableMapOf": "fun mutableMapOf<K, V>(pairs: Any...): MutableMap<K, V>",
|
||||
"ByteSlice": "fun ByteSlice(value: String | Int): ByteSlice",
|
||||
"append": "fun append<T>(values: List<T>, value: T): List<T>",
|
||||
"keys": "fun keys<K, V>(values: Map<K, V>): List<K>",
|
||||
"goAssert": "fun goAssert<T>(value: Any): T",
|
||||
"len": "fun len(value: Any): Int",
|
||||
"cap": "fun cap(value: Any): Int",
|
||||
"make": "fun make<T>(size: Int): T",
|
||||
"new": "fun new<T>(): *T",
|
||||
"copy": "fun copy(target: Any, source: Any): Int",
|
||||
"delete": "fun delete(map: Any, key: Any): Unit",
|
||||
"close": "fun close(channel: Any): Unit",
|
||||
"panic": "fun panic(value: Any): Unit",
|
||||
"recover": "fun recover(): Any",
|
||||
"string": "fun string(value: Any): String",
|
||||
"int": "fun int(value: Any): Int",
|
||||
"float64": "fun float64(value: Any): Double",
|
||||
"bool": "fun bool(value: Any): Boolean",
|
||||
"sql": "typed PostgreSQL query DSL",
|
||||
"set": "fun set(target: Any, value: Any): Unit",
|
||||
"now": "fun now(): time.Time",
|
||||
"runBlocking": "fun runBlocking(block: suspend () -> Unit): Unit",
|
||||
"coroutineScope": "suspend fun coroutineScope(block: suspend () -> Unit): Unit",
|
||||
"launch": "suspend fun launch(block: suspend () -> Unit): Unit",
|
||||
"async": "suspend fun async<T>(block: suspend () -> T): Deferred<T>",
|
||||
"delay": "suspend fun delay(ms: Int): Unit",
|
||||
"withTimeout": "suspend fun withTimeout(ms: Int, block: suspend () -> Unit): Unit",
|
||||
"isActive": "suspend fun isActive(): Boolean",
|
||||
}
|
||||
|
||||
func contains(values []string, needle string) bool {
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ fun main() {
|
|||
t.Fatalf("unexpected builtin diagnostic: %+v", diagnostic)
|
||||
}
|
||||
}
|
||||
for _, name := range []string{"ByteSlice", "append", "len", "sql", "set", "now"} {
|
||||
for _, name := range []string{"ByteSlice", "append", "keys", "goAssert", "len", "sql", "set", "now"} {
|
||||
if !isBuiltin(name) {
|
||||
t.Fatalf("%s is not registered as builtin", name)
|
||||
}
|
||||
|
|
@ -694,7 +694,7 @@ fun runWorker(name: String) {
|
|||
}
|
||||
|
||||
fun main() {
|
||||
go runWorker("alice")
|
||||
runBlocking { launch { runWorker("alice") } }
|
||||
}
|
||||
`)
|
||||
|
||||
|
|
@ -717,9 +717,11 @@ fun writer(ch: Channel<Int>) {
|
|||
|
||||
fun main() {
|
||||
val ch = Channel<Int>()
|
||||
go writer(ch)
|
||||
select {
|
||||
ch -> println(it)
|
||||
runBlocking {
|
||||
launch { writer(ch) }
|
||||
select {
|
||||
ch -> println(it)
|
||||
}
|
||||
}
|
||||
val v = ch.read()
|
||||
println(v)
|
||||
|
|
@ -778,22 +780,11 @@ fun main() {
|
|||
`)
|
||||
|
||||
state := buildDocumentState(text)
|
||||
if state.program == nil {
|
||||
t.Fatal("expected parsed program")
|
||||
if state.program != nil {
|
||||
t.Fatal("worker syntax should no longer parse")
|
||||
}
|
||||
if len(state.diagnostics) != 0 {
|
||||
t.Fatalf("expected no diagnostics, got %+v", state.diagnostics)
|
||||
}
|
||||
|
||||
var counterDetail string
|
||||
for _, sym := range state.symbols {
|
||||
if sym.Kind == symbolKindVariable && sym.Name == "counter" {
|
||||
counterDetail = sym.Detail
|
||||
break
|
||||
}
|
||||
}
|
||||
if counterDetail != "val counter: Counter" {
|
||||
t.Fatalf("unexpected counter detail: %q", counterDetail)
|
||||
if len(state.diagnostics) == 0 {
|
||||
t.Fatal("expected removed worker syntax diagnostic")
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue