plum

#treesitter#compiler#wasm

git clone https://git.pyrossh.dev/plum

A statically typed, imperative programming language inspired by rust, python


670c97c — Peter John 2026-11-09T17:21:04+05:30
Checker: a spread's source fixes the type arguments before the fields
compiler/checker/src/callcheck.rs CHANGED
@@ -115,6 +115,16 @@ pub(crate) fn inferClassCallRaw(
115
115
  // separate class-construction path needed.
116
116
  Some(info) if !info.field_names.is_empty() => {
117
117
  let (owner, result, mut binds) = startVariant(info, &explicit, expected);
118
+ // A spread's source fixes the type arguments first, so a field whose value
119
+ // is pinned only by them (`Outer(..o, h: Holder.of(2))`) gets them as its
120
+ // expected type. The source itself is checked after the fields.
121
+ if let Some(spread) = &call.spread {
122
+ if matches!(spread.kind, ast::ExprKind::Var(_) | ast::ExprKind::Self_ | ast::ExprKind::TypeName(_)) {
123
+ if let Ok(source) = inferExpr(spread, env, ctx) {
124
+ bindMatch(&result, &source, &mut binds);
125
+ }
126
+ }
127
+ }
118
128
  // Closure-valued fields last (same two passes as `checkCallArgs`), so
119
129
  // `Num(add: |a, b| a + b, zero: 0)` learns `T = Int` from `zero` first.
120
130
  let (closures, others): (Vec<&ast::FieldArg>, Vec<&ast::FieldArg>) = call
examples/games/kids/balloon_pop.plum CHANGED
@@ -427,8 +427,7 @@ test "a popped balloon comes back at the bottom"
427
427
 
428
428
  test "every tenth pop starts a party that ends"
429
429
  fresh := withCentred(newGame())
430
- nine: Store[State, Msg] := Store.of(State(..fresh.state(), pops: 9))
430
+ g := Game(..fresh, store: Store.of(State(..fresh.state(), pops: 9)))
431
- g := Game(..fresh, store: nine)
432
431
  assert !g.state().partying()
433
432
  assert !skyOf(g).t.find(PartyId).unwrap().shown()
434
433
  t := tick(io, g, pressAt(400.0, 300.0), 0.01)
tests/core/spread_pins_generics.plum ADDED
@@ -0,0 +1,21 @@
1
+ import std/Int
2
+ import std/Str
3
+ import std/List
4
+
5
+ # A spread's source fixes the type arguments of the struct it builds, so a field whose
6
+ # value is pinned only by them gets them: `Holder.of(2)` below is a `Holder[Int, Str]`
7
+ # because `o` is an `Outer[Int, Str]`. (It was compiled with `M` unknown, and code
8
+ # generation failed with "unknown method 'Holder.of'".)
9
+ struct Holder[T, M](items: List[T], tags: List[M]) =
10
+ fun of(x: T) -> Holder[T, M] = Holder(items: [x], tags: Nil)
11
+
12
+ struct Outer[T, M](h: Holder[T, M], n: Int)
13
+
14
+ test "a generic call in a spread's field takes the type arguments of the spread's source"
15
+ o: Outer[Int, Str] := Outer(h: Holder(items: [1], tags: ["a"]), n: 7)
16
+ p := Outer(..o, h: Holder.of(2))
17
+ assert p.h.items.length() == 1
18
+ assert p.h.tags.length() == 0
19
+ assert p.n == 7
20
+ q := Outer(..p, h: Holder(items: p.h.items, tags: ["b", "c"]))
21
+ assert q.h.tags.length() == 2