You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inferred return type is not visible to a caller that precedes the definition #1196
Spec §9.1 (D43): an unannotated function's return type is the type of its tail. A caller that appears earlier in the file than the definition does not see that type.
type C { n: i32 }
impl C:
fn go(x: i32) -> bool: x > 0 and later_pred()
fn later_pred(): 1 + 1 == 2
fn main:
let c = C { n: 1 }
if c.go(1): print("ok")
error: right operand of logical operator must be bool
--> fwd.w:3:28
Expected: prints ok. Declaration order must not matter. Moving later_pred above impl C, or writing -> bool, makes it pass.
Workaround in use: -> bool on codegen_c_abi_aarch64 / codegen_c_abi_sysv_x86_64 in src/Codegen.w (the #1195 fix); remove when this is fixed.
Verified on the pinned seed v0.15.1.10: this predates D43. Any forward call to an unannotated function fails, free function or method.
Fix on branch fix-filed-issues: check_bodies types the functions that take their type from their body first, then the ones with a written return type or a fixed contract (main, tests). On-demand checking of a callee mid-caller is not possible: the body check resets per-function state rather than saving it.
Remaining shape: an unannotated function calling an unannotated function declared after it. That call is recorded and, once every body is typed, reported only if the callee turned out to produce a value (a call to a procedure was typed correctly all along — the compiler's own source has such calls). Ordering those by dependency needs the call graph before Sema; name resolution already records uses per definition, which is the place to get it from.
Triage 2026-10-25, with v0.15.3.0 (main a261b65): does not reproduce; b11637b (#1205) types a function from its body before callers that precede it.
$ cat main.w
type C { n: i32 }
impl C:
fn go(x: i32) -> bool: x > 0 and later_pred()
fn later_pred(): 1 + 1 == 2
fn main:
let c = C { n: 1 }
if c.go(1): print("ok")
$ with run main.w
ok
Activity
ehartford commentedon Sep 19, 2026
Verified on the pinned seed v0.15.1.10: this predates D43. Any forward call to an unannotated function fails, free function or method.
Fix on branch
fix-filed-issues:check_bodiestypes the functions that take their type from their body first, then the ones with a written return type or a fixed contract (main, tests). On-demand checking of a callee mid-caller is not possible: the body check resets per-function state rather than saving it.Remaining shape: an unannotated function calling an unannotated function declared after it. That call is recorded and, once every body is typed, reported only if the callee turned out to produce a value (a call to a procedure was typed correctly all along — the compiler's own source has such calls). Ordering those by dependency needs the call graph before Sema; name resolution already records uses per definition, which is the place to get it from.
Type a function from its body before the callers that have a written …
Sema: a function returning a view is checked before its callers — ret…
Ownership: D72 liveness byte, D73 assignment-as-read, validator leak/…
ehartford commentedon Oct 25, 2026
Triage 2026-10-25,
with v0.15.3.0(main a261b65): does not reproduce; b11637b (#1205) types a function from its body before callers that precede it.