convert_from_struct.carbon 844 B

123456789101112131415161718192021222324252627282930
  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. // RUN: %{explorer} %s 2>&1 | \
  6. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes=false %s
  7. // RUN: %{explorer} --parser_debug --trace_file=- %s 2>&1 | \
  8. // RUN: %{FileCheck} --match-full-lines --allow-unused-prefixes %s
  9. // AUTOUPDATE: %{explorer} %s
  10. // CHECK: result: 5
  11. package ExplorerTest api;
  12. class Point(T:! Type) {
  13. var x: T;
  14. var y: T;
  15. }
  16. fn GetX[T:! Type](pt: Point(T)) -> T {
  17. return pt.x;
  18. }
  19. fn GetY(T:! Type, pt: Point(T)) -> T {
  20. return pt.y;
  21. }
  22. fn Main() -> i32 {
  23. var p: Point(i32) = {.x = 1, .y = 2};
  24. // TODO: Should `GetX({.x = 1, .y = 2})` work? See #1251.
  25. return GetX(p) + GetY(i32, {.x = 3, .y = 4});
  26. }