class_tuples.carbon 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
  5. //
  6. // AUTOUPDATE
  7. // TIP: To test this file alone, run:
  8. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/tuple/class_tuples.carbon
  9. // TIP: To dump output, run:
  10. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/class_tuples.carbon
  11. // Versus the no_prelude basics.carbon, this tests some interactions with
  12. // `class`.
  13. // --- fail_element_type_mismatch.carbon
  14. library "[[@TEST_NAME]]";
  15. class C {}
  16. class D {}
  17. var c: C;
  18. var d: D;
  19. // CHECK:STDERR: fail_element_type_mismatch.carbon:[[@LINE+7]]:19: error: cannot implicitly convert expression of type `C` to `C*` [ConversionFailure]
  20. // CHECK:STDERR: var x: (C*, C*) = (c, d);
  21. // CHECK:STDERR: ^~~~~~
  22. // CHECK:STDERR: fail_element_type_mismatch.carbon:[[@LINE+4]]:19: note: type `C` does not implement interface `Core.ImplicitAs(C*)` [MissingImplInMemberAccessNote]
  23. // CHECK:STDERR: var x: (C*, C*) = (c, d);
  24. // CHECK:STDERR: ^~~~~~
  25. // CHECK:STDERR:
  26. var x: (C*, C*) = (c, d);
  27. // --- fail_nested_incomplete.carbon
  28. library "[[@TEST_NAME]]";
  29. class Complete {}
  30. class Incomplete;
  31. // CHECK:STDERR: fail_nested_incomplete.carbon:[[@LINE+7]]:8: error: binding pattern has incomplete type `(Complete, Incomplete)` in name binding declaration [IncompleteTypeInBindingDecl]
  32. // CHECK:STDERR: var t: (Complete, Incomplete);
  33. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~~
  34. // CHECK:STDERR: fail_nested_incomplete.carbon:[[@LINE-5]]:1: note: class was forward declared here [ClassForwardDeclaredHere]
  35. // CHECK:STDERR: class Incomplete;
  36. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  37. // CHECK:STDERR:
  38. var t: (Complete, Incomplete);
  39. var p: Incomplete* = &t[1];
  40. // --- fail_type_assign.carbon
  41. library "[[@TEST_NAME]]";
  42. class C {}
  43. // CHECK:STDERR: fail_type_assign.carbon:[[@LINE+7]]:16: error: cannot implicitly convert expression of type `type` to `C` [ConversionFailure]
  44. // CHECK:STDERR: var x: (C, ) = (C, );
  45. // CHECK:STDERR: ^~~~~
  46. // CHECK:STDERR: fail_type_assign.carbon:[[@LINE+4]]:16: note: type `type` does not implement interface `Core.ImplicitAs(C)` [MissingImplInMemberAccessNote]
  47. // CHECK:STDERR: var x: (C, ) = (C, );
  48. // CHECK:STDERR: ^~~~~
  49. // CHECK:STDERR:
  50. var x: (C, ) = (C, );
  51. // --- fail_value_as_type.carbon
  52. library "[[@TEST_NAME]]";
  53. class C {}
  54. var c: C;
  55. // CHECK:STDERR: fail_value_as_type.carbon:[[@LINE+7]]:8: error: cannot implicitly convert non-type value of type `C` to `type` [ConversionFailureNonTypeToFacet]
  56. // CHECK:STDERR: var x: c;
  57. // CHECK:STDERR: ^
  58. // CHECK:STDERR: fail_value_as_type.carbon:[[@LINE+4]]:8: note: type `C` does not implement interface `Core.ImplicitAs(type)` [MissingImplInMemberAccessNote]
  59. // CHECK:STDERR: var x: c;
  60. // CHECK:STDERR: ^
  61. // CHECK:STDERR:
  62. var x: c;