Infer map literal types

This commit is contained in:
sergeych committed 2026-02-05 20:31:20 +03:00
1 parent de9ac14e33
commit 7a286f2e06
4 files changed
+152 -1

No files matched your search

+7
View File
@@ -37,6 +37,7 @@ Generic types are invariant by default. You can specify declaration-site varianc
- Literals set obvious types (`1` is `Int`, `1.0` is `Real`, etc.).
- Empty list literals default to `List<Object>` unless constrained by context.
- Non-empty list literals infer element type as a union of element types.
- Map literals infer key and value types; named keys are `String`.
Examples:
@@ -44,6 +45,12 @@ Examples:
val b = [1, "two", true] // List<Int | String | Bool>
val c: List<Int> = [] // List<Int>
val m1 = { "a": 1, "b": 2 } // Map<String, Int>
val m2 = { "a": 1, "b": "x" } // Map<String, Int | String>
val m3 = { ...m1, "c": true } // Map<String, Int | Bool>
Map spreads carry key/value types when possible.
Spreads propagate element type when possible:
val base = [1, 2]