fail_implicit_convert_with_as.carbon 661 B

12345678910111213141516171819202122232425
  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 A {
  8. var a: i32;
  9. }
  10. class B {
  11. var b: i32;
  12. }
  13. impl A as As(B) {
  14. fn Convert[self: Self]() -> B { return {.b = self.a}; }
  15. }
  16. fn Main() -> i32 {
  17. var a: (i32, A) = (1, {.a = 2});
  18. // CHECK:STDERR: COMPILATION ERROR: fail_implicit_convert_with_as.carbon:[[@LINE+1]]: type error in initializer of variable: '(i32, class A)' is not implicitly convertible to '(i32, class B)'
  19. var b: (i32, B) = a;
  20. return b[1].b;
  21. }