Skip to content

12. Errors and debugging ​

Compiler failures are written as diagnostics to standard error and exit nonzero. Generated functions use ordinary Go values and errors; they do not include a Stated runtime or process protocol.

Complete failure example ​

txt
Define filter-and-double as a function.
It accepts an integer sequence named input and an integer named threshold.
Collect the input values in encounter order into a fresh sequence. Retain each value only when it is greater than the threshold. Replace each retained value with the doubled value of that value before appending it.
go
package generated

import (
	"errors"
	"math"
)

func FilterAndDouble(p0 []int64, p1 int64) ([]int64, error) {
	result := make([]int64, 0)
	for _, value := range p0 {
		if value > p1 {
			if value > math.MaxInt64/2 || value < math.MinInt64/2 {
				return nil, errors.New("integer overflow")
			}
			result = append(result, value+value)
		}
	}
	return result, nil
}

If checked doubling overflows, the emitted function returns an error. No runtime-specific diagnostic category or step counter is added.

Exercise ​

Change the threshold to 9223372036854775807. Should the same maximum integer still overflow?

Verified solution

No. The strict comparison rejects it, so doubling is skipped and the verified result is []. Static validation still checks that the transformation is well-formed.

← Defining reusable vocabulary · Reference →

Stated compiles controlled English deterministically. It does not call an LLM at compile time.