size_mismatch.carbon 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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/size_mismatch.carbon
  10. // TIP: To dump output, run:
  11. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/size_mismatch.carbon
  12. // --- fail_assign_from_empty.carbon
  13. library "[[@TEST_NAME]]";
  14. // CHECK:STDERR: fail_assign_from_empty.carbon:[[@LINE+4]]:16: error: cannot initialize tuple of 1 element from tuple with 0 elements [TupleInitElementCountMismatch]
  15. // CHECK:STDERR: var x: ((),) = ();
  16. // CHECK:STDERR: ^~
  17. // CHECK:STDERR:
  18. var x: ((),) = ();
  19. // --- fail_assign_to_empty.carbon
  20. library "[[@TEST_NAME]]";
  21. // CHECK:STDERR: fail_assign_to_empty.carbon:[[@LINE+4]]:13: error: cannot initialize tuple of 0 elements from tuple with 1 element [TupleInitElementCountMismatch]
  22. // CHECK:STDERR: var x: () = ((),);
  23. // CHECK:STDERR: ^~~~~
  24. // CHECK:STDERR:
  25. var x: () = ((),);
  26. // --- fail_assign_nested.carbon
  27. library "[[@TEST_NAME]]";
  28. // CHECK:STDERR: fail_assign_nested.carbon:[[@LINE+4]]:32: error: cannot initialize tuple of 2 elements from tuple with 3 elements [TupleInitElementCountMismatch]
  29. // CHECK:STDERR: var x: (((), ()), ((), ())) = (((), (), ()), ((), (), ()));
  30. // CHECK:STDERR: ^~~~~~~~~~~~
  31. // CHECK:STDERR:
  32. var x: (((), ()), ((), ())) = (((), (), ()), ((), (), ()));
  33. // --- fail_too_few_elements.carbon
  34. library "[[@TEST_NAME]]";
  35. // CHECK:STDERR: fail_too_few_elements.carbon:[[@LINE+4]]:19: error: cannot initialize tuple of 2 elements from tuple with 1 element [TupleInitElementCountMismatch]
  36. // CHECK:STDERR: var x: ((), ()) = ((), );
  37. // CHECK:STDERR: ^~~~~~
  38. // CHECK:STDERR:
  39. var x: ((), ()) = ((), );