soma.cell

E0044: variant_shape

E0044 variant_shape — a variant built with the wrong fields.

A compile-time error of soma check, the checker of the Soma programming language (soma explain E0044).

The rule

A record or variant literal must give exactly the fields its cell type declares; here one field is missing. Soma refuses it at check time because a missing field would otherwise read as () later in the program. Add the missing field (or remove the extra one) so the literal matches the declaration.

A program that triggers it

wrong.cell

cell type Shipment { variants { Shipment { order_id: String, carrier: String, weight_grams: Int } } }

cell Dispatch {
    face {
        signal label(order_id: String, weight_grams: Int) -> String
    }
    on label(order_id: String, weight_grams: Int) {
        let s = Shipment { order_id: order_id, weight_grams: weight_grams }
        return "{s.order_id} via {s.carrier}"
    }
}

What soma check prints:

$ soma check wrong.cell
error: `Shipment { … }` is missing the field `carrier`
  --> wrong.cell:8:38
  |
8 |         let s = Shipment { order_id: order_id, weight_grams: weight_grams }
  |                                      ^
  = code: E0044
✗ 1 error(s), 0 warning(s).

The fix field of soma check --json: `Shipment { … }` is missing the field `carrier`

On line 8, let s = Shipment { order_id: order_id, weight_grams: weight_grams } becomes let s = Shipment { order_id: order_id, carrier: "UPS", weight_grams: weight_grams }.

wrong.cell → right.cell

--- wrong.cell
+++ right.cell
@@ -6,5 +6,5 @@
     }
     on label(order_id: String, weight_grams: Int) {
-        let s = Shipment { order_id: order_id, weight_grams: weight_grams }
+        let s = Shipment { order_id: order_id, carrier: "UPS", weight_grams: weight_grams }
         return "{s.order_id} via {s.carrier}"
     }

With the fix, soma check accepts the program:

$ soma check right.cell
✓ All checks passed.