convert_from_struct.carbon 600 B

123456789101112131415161718192021222324252627
  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. //
  5. // NOAUTOUPDATE
  6. package ExplorerTest api;
  7. class Point(T:! type) {
  8. var x: T;
  9. var y: T;
  10. }
  11. fn GetX[T:! type](pt: Point(T)) -> T {
  12. return pt.x;
  13. }
  14. fn GetY(T:! type, pt: Point(T)) -> T {
  15. return pt.y;
  16. }
  17. fn Main() -> i32 {
  18. var p: Point(i32) = {.x = 1, .y = 2};
  19. // TODO: Should `GetX({.x = 1, .y = 2})` work? See #1251.
  20. return GetX(p) + GetY(i32, {.x = 3, .y = 4});
  21. }
  22. // CHECK:STDOUT: result: 5