carbon-lang icon indicating copy to clipboard operation
carbon-lang copied to clipboard

Termination rule should also apply to instantiating specifics

Open josh11b opened this issue 8 months ago • 0 comments
trafficstars

In this example:

interface I {
  let T:! type;
  default fn F() -> T;
}

fn I.F() -> T {
  class C {
    // `I` is complete, but `I.F`'s default
    // value is still being defined.
    impl as I where .T = i32 {}
  }
}

If the default definition of I.F is eveer used, it will lead to an infinite instantiation loop. This is because forming the specific for a given type U will trigger creation of a new class C(U), which itself has an impl of I that uses the default value of I.F.

We should apply the termination check to formation of specifics to detect this problem, since each instantiation is strictly more complex.

josh11b avatar Mar 21 '25 21:03 josh11b