Make C++ types impl Core.Default. (#6962)

C++ classes that are default-constructible now implement `Core.Default`
by calling the default constructor.
This commit is contained in:
Richard Smith
2026-03-25 21:07:24 +00:00
committed by GitHub
parent 311670c84a
commit 37b238fa28
49 changed files with 1069 additions and 426 deletions
@@ -8,6 +8,12 @@ package Core library "prelude/parts/default";
interface DefaultOrUnformed { fn Op() -> Self; }
interface Default { fn Op() -> Self; }
final impl forall [T:! Default] T as DefaultOrUnformed {
fn Op() -> Self { return T.(Default.Op)(); }
}
// In tests, just allow any type to be default-initialized as a no-op.
// TODO: This is a hack to allow existing tests to contiue working.
impl forall [T:! type] T as DefaultOrUnformed {