fail_derived_to_base.carbon 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. //
  7. // AUTOUPDATE
  8. // TIP: To test this file alone, run:
  9. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/inheritance/fail_derived_to_base.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/inheritance/fail_derived_to_base.carbon
  12. base class A1 {
  13. var a: i32;
  14. }
  15. base class A2 {
  16. var a: i32;
  17. }
  18. class B2 {
  19. extend base: A2;
  20. var b: i32;
  21. }
  22. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+7]]:38: error: cannot implicitly convert expression of type `B2*` to `A1*` [ConversionFailure]
  23. // CHECK:STDERR: fn ConvertUnrelated(p: B2*) -> A1* { return p; }
  24. // CHECK:STDERR: ^~~~~~~~~
  25. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+4]]:38: note: type `B2*` does not implement interface `Core.ImplicitAs(A1*)` [MissingImplInMemberAccessInContext]
  26. // CHECK:STDERR: fn ConvertUnrelated(p: B2*) -> A1* { return p; }
  27. // CHECK:STDERR: ^~~~~~~~~
  28. // CHECK:STDERR:
  29. fn ConvertUnrelated(p: B2*) -> A1* { return p; }
  30. class Incomplete;
  31. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+7]]:47: error: cannot implicitly convert expression of type `Incomplete*` to `A2*` [ConversionFailure]
  32. // CHECK:STDERR: fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
  33. // CHECK:STDERR: ^~~~~~~~~
  34. // CHECK:STDERR: fail_derived_to_base.carbon:[[@LINE+4]]:47: note: type `Incomplete*` does not implement interface `Core.ImplicitAs(A2*)` [MissingImplInMemberAccessInContext]
  35. // CHECK:STDERR: fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }
  36. // CHECK:STDERR: ^~~~~~~~~
  37. // CHECK:STDERR:
  38. fn ConvertIncomplete(p: Incomplete*) -> A2* { return p; }