default.carbon 709 B

123456789101112131415161718192021
  1. // Part of the Carbon Language project, under the Apache License v2.0 with LLVM
  2. // Exceptions. See /LICENSE for license information.
  3. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  4. // --- min_prelude/parts/default.carbon
  5. package Core library "prelude/parts/default";
  6. interface DefaultOrUnformed { fn Op() -> Self; }
  7. interface Default { fn Op() -> Self; }
  8. final impl forall [T:! Default] T as DefaultOrUnformed {
  9. fn Op() -> Self { return T.(Default.Op)(); }
  10. }
  11. // In tests, just allow any type to be default-initialized as a no-op.
  12. // TODO: This is a hack to allow existing tests to contiue working.
  13. impl forall [T:! type] T as DefaultOrUnformed {
  14. fn Op() -> Self = "make_uninitialized";
  15. }