class_tuples.carbon 3.0 KB

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