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
A default trait method that calls the type's other static methods (Self.a(x)) emits invalid LLVM: an extra receiver argument #3335
trait P:
fn a(x: &str) -> Option[Self]
fn why(x: &str) -> str: ""
fn must(x: &str, name: &str, line: i32) -> Self:
let got = Self.a(x)
if got.is_none(): panic(f"cannot parse {name} from \"{x}\"{Self.why(x)}\n at {line}")
got.unwrap()
impl P for i32:
fn a(x: &str) -> Option[i32]: if x == "1": Some(1) else: None
fn why(x: &str) -> str: ": overflow"
type C { v: i32 }
impl P for C:
fn a(x: &str) -> Option[C]: Some(C { v: 9 })
fn main:
print(i32.must("1", "i32", 3))
print(C.must("x", "C", 4).v)
Incorrect number of arguments passed to called function!
%6 = call { i32, [1 x i32] } @i32.P.a(%str zeroinitializer, %str %.fca.1.insert)
===== INVALID LLVM FUNCTION i32.must =====
Inside the default body, Self.a(x) is lowered with a receiver slot the static method does not have.
With a match in the default body instead of the let/if:
fn must(x: &str, name: &str, line: i32) -> Self:
match Self.a(x):
Some(v) => v
None => panic("no")
Sema reports internal error: conflicting contextual join decisions for one expression (sig -1: first expected i32 [3] final i32 [3], now expected C [310] final C [310]): the join decision is recorded per tree node, and the one default body is checked once per implementing type.
Both on the installed compiler (v0.16.0.8). Found while building D203/D204; that work uses a generic free function instead.
The join conflict, exact line. lldb, breakpoint Sema.resolve_contextual_join: both impls reach it with the same report_node (20151), called from check_trait_default_method_body_for_impl (SemaCheck.w:6751) under collect_declarations. Each impl is meant to have its own copy of a default body (AstPool.clone_default_method_bodies), but that pass runs in Frontend.w after the comptime phase; the first Sema pass checks the trait's one shared body for every impl. The join decision is keyed (current_fn_sig_idx, node) and current_fn_sig_idx is not set while a default body is checked (the message prints sig -1), so the second impl's decision meets the first's. Fix: check the default body under the impl method's own signature (current_fn_sig_idx = sig_idx, as current_effect_body already is, #1827).
The invalid LLVM, narrowed. One impl is enough (impl P for C alone, let got = Self.a(x); got.unwrap()): call @C.P.a(%str zeroinitializer, %str …), two arguments to a one-parameter function. a is declared in the trait with no receiver use and is called as a static (C.a(x)) everywhere else; inside the default body Self.a(x) is lowered as an instance call with a receiver slot. The default method does not appear in --dump-mir.
A tool that stayed silent.with analyze dl.w audit:resolution says violations=0 ok on the program that emits the invalid call.
Related, to settle first. §9.5 says a fn inside an impl is an instance method, and §11 speaks of a trait's static method (fn one() -> Self). In an ordinary impl, fn a(x: &str) -> Option[Self] then Self.a(x) in a sibling is refused with "return type does not implement Default" at the let, which is the wrong message whatever the rule is. Which trait methods are static, and how a default body calls one, needs the spec read against the implementation before the lowering is changed.
Activity
ehartford commentedon Nov 14, 2026
Findings (installed compiler, main 4c525fb).
The join conflict, exact line. lldb, breakpoint
Sema.resolve_contextual_join: both impls reach it with the samereport_node(20151), called fromcheck_trait_default_method_body_for_impl(SemaCheck.w:6751) undercollect_declarations. Each impl is meant to have its own copy of a default body (AstPool.clone_default_method_bodies), but that pass runs inFrontend.wafter the comptime phase; the first Sema pass checks the trait's one shared body for every impl. The join decision is keyed(current_fn_sig_idx, node)andcurrent_fn_sig_idxis not set while a default body is checked (the message printssig -1), so the second impl's decision meets the first's. Fix: check the default body under the impl method's own signature (current_fn_sig_idx = sig_idx, ascurrent_effect_bodyalready is, #1827).The invalid LLVM, narrowed. One impl is enough (
impl P for Calone,let got = Self.a(x);got.unwrap()):call @C.P.a(%str zeroinitializer, %str …), two arguments to a one-parameter function.ais declared in the trait with no receiver use and is called as a static (C.a(x)) everywhere else; inside the default bodySelf.a(x)is lowered as an instance call with a receiver slot. The default method does not appear in--dump-mir.A tool that stayed silent.
with analyze dl.w audit:resolutionsaysviolations=0 okon the program that emits the invalid call.Related, to settle first. §9.5 says a
fninside animplis an instance method, and §11 speaks of a trait's static method (fn one() -> Self). In an ordinary impl,fn a(x: &str) -> Option[Self]thenSelf.a(x)in a sibling is refused with "return type does not implement Default" at thelet, which is the wrong message whatever the rule is. Which trait methods are static, and how a default body calls one, needs the spec read against the implementation before the lowering is changed.A function that reaches an assigner of a destroyer global assigns it (#…
Self.make(x) in a method body calls the static method: MIR reads Sema…