Skip to content

Commit ee5d5f4

Browse files
committed
update docs and tests
1 parent 60f98b2 commit ee5d5f4

2 files changed

Lines changed: 389 additions & 2 deletions

File tree

docs/language.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ Annotations have four effects:
501501
2. **Seeded type inference.** `Infer()` plants the annotated types into `FuncTypeInfo.ParamTypes`/`ReturnType` before walking the body. The inferrer treats annotated params as ground truth and will not widen them to `interface{}` if a later assignment is dynamic. Annotated returns are not overwritten by the inferred return type.
502502
3. **Typed Go signatures.** When the annotated type is a primitive (`int`, `float`, `string`, `bool`), codegen emits a typed Go signature (`func rugofn_add(a int, b int) int`) instead of the default `func(... interface{}) interface{}`. The return path inserts a `rugo_to_*` coercion if the body produced a dynamic value, so calls into runtime helpers (e.g. `math.sqrt`) still work without manual casts.
503503
4. **Body/annotation mismatch detection.** After inference, the compiler walks every annotated function body and flags two patterns the inferrer can prove are wrong: reassigning an annotated parameter to a value of a concretely conflicting type (e.g. `a = "hello"` inside `def f(a : int)`) and returning a value whose inferred type conflicts with the annotated return type. Errors point at the rugo source line with a structured message instead of a Go-level compiler error. Assignment is strict (the generated Go has a concrete variable, no coercion at the reassignment site); returns are permissive in the numeric family and for `string`/`bool`/`any` (the codegen inserts coercion). Pass `--no-infer` to skip the check.
504+
5. **Call-site argument validation (literal args).** When a *literal* argument (number, string, bool, nil, array, hash, or `-N`/`!b` over a literal) is passed to a user-defined function with an annotated parameter, the compiler flags concretely-conflicting cases at compile time (e.g. `f("oops")` where `f` is `def f(a : int)`). The check uses the same permissive compatibility rule as returns: numeric family is mutually compatible, `string`/`bool`/`any` accept anything. Non-literal arguments (variables, calls, dot expressions) are not flagged — only the inferrer can reason about those, and adaptive widening already keeps them silent. Module-style `ns.f(...)` calls are also skipped. Pass `--no-infer` to disable.
504505
505506
Coverage is reported by `rugo emit --stats`:
506507

0 commit comments

Comments
 (0)