fail_convert.carbon 878 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. // AUTOUPDATE
  6. // RUN: %{not} %{explorer-run}
  7. // RUN: %{not} %{explorer-run-trace}
  8. package ExplorerTest api;
  9. class IntLike {
  10. var n: i32;
  11. }
  12. impl i32 as ImplicitAs(IntLike) {
  13. fn Convert[self: i32]() -> IntLike { return {.n = self}; }
  14. }
  15. fn Main() -> i32 {
  16. var arr: [i32; 4] = (0, 1, 2, 3);
  17. // TODO: We should accept this, but currently have nowhere in our
  18. // representation to describe the conversion.
  19. for (x: IntLike in arr) {
  20. Print("{0}", x.n);
  21. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/for/fail_convert.carbon:[[@LINE+3]]: type error in `for` pattern
  22. // CHECK:STDERR: expected: i32
  23. // CHECK:STDERR: actual: class IntLike
  24. }
  25. return 0;
  26. }