convert_from_struct.carbon 651 B

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