GALA-E0033 — Untyped lambda parameter

What it means. A lambda parameter has no type annotation and the surrounding context supplies no expected type to infer one from. The canonical case is a lambda bound to a val with no declared type.


Code that triggers it

func main() {
    val f = (x) => x + 1          // nothing tells the compiler what x is
    Println(f(2))
}

There is nothing to infer x from. The only way to give it a type would be to emit any, which violates GALA’s concrete-types invariant and produces Go that either fails to compile or silently erases the type.


Compiler message

error[GALA-E0033]: lambda parameter "x" has no type and none can be inferred from context
  --> e0033.gala:4:14
  |
4 |     val f = (x) => x + 1
  |              ^ annotate it
  |
  = hint: annotate it (e.g. `(x int) => …`) or use the lambda in a typed context (typed val, function argument, or return)

How to fix it

Annotate the parameter:

val f = (x int) => x + 1

…or put the lambda in a typed context, which threads the declared signature into it so the parameter types are inferred:

val f func(int) int = (x) => x + 1        // declared val type
arr.Map((x) => x * 2)                     // method argument
func mk() func(int) int = (x) => x + 1    // function return

The third form is why idiomatic GALA rarely annotates lambdas: pass them straight to Map, Filter, FoldLeft, or a typed parameter and the types flow in.


Why the rule exists

A lambda in a typed slot draws its parameter and return types from that slot. A bare lambda initializer has no such slot, so an annotation is the only way to keep the generated Go concrete. This parameter used to default to any with a warning; the error surfaces the problem at its source instead of deferring it to a confusing Go compile error — or a silent any.

Scope. Any unannotated lambda parameter whose type cannot be inferred: no expected type, a callee whose signature the transpiler does not know, or a callee parameter type that could not be resolved — for example a Go function whose package does not type-check because one of its imports cannot be found:

[SemanticError GALA-E0033] lib.gala:5:50 lambda parameter "c" has no type: Serve expects a function here whose parameter 1 has a type that could not be resolved (hint: check that the package declaring Serve type-checks — every package it imports must resolve — or annotate the parameter (e.g. `(c T) => …`))

Fix the callee’s package so it type-checks, or annotate the parameter. A parameter whose slot is typed any is still lowered to any: as the callee declares it, or because the slot names a type parameter no argument determines while the call’s arguments determine others. When they determine none, the parameter has no type and this error fires.