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