fail_implicit_convert_with_as.carbon 751 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. // AUTOUPDATE
  6. // RUN: %{not} %{explorer-run}
  7. // RUN: %{not} %{explorer-run-trace}
  8. package ExplorerTest api;
  9. class A {
  10. var a: i32;
  11. }
  12. class B {
  13. var b: i32;
  14. }
  15. external impl A as As(B) {
  16. fn Convert[self: Self]() -> B { return {.b = self.a}; }
  17. }
  18. fn Main() -> i32 {
  19. var a: (i32, A) = (1, {.a = 2});
  20. // CHECK:STDERR: COMPILATION ERROR: {{.*}}/explorer/testdata/tuple/fail_implicit_convert_with_as.carbon:[[@LINE+1]]: type error in name binding: '(i32, class A)' is not implicitly convertible to '(i32, class B)'
  21. var b: (i32, B) = a;
  22. return 0;
  23. }