fail_empty_tuple_access.carbon 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // AUTOUPDATE
  6. // TIP: To test this file alone, run:
  7. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/index/fail_empty_tuple_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/index/fail_empty_tuple_access.carbon
  10. fn F() {}
  11. fn Run() {
  12. // CHECK:STDERR: fail_empty_tuple_access.carbon:[[@LINE+3]]:3: ERROR: Tuple element index `0` is past the end of type `()`.
  13. // CHECK:STDERR: F()[0];
  14. // CHECK:STDERR: ^~~~~~
  15. F()[0];
  16. }
  17. // CHECK:STDOUT: --- fail_empty_tuple_access.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  21. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  22. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  23. // CHECK:STDOUT: %Run.type: type = fn_type @Run [template]
  24. // CHECK:STDOUT: %Run: %Run.type = struct_value () [template]
  25. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: file {
  29. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  30. // CHECK:STDOUT: .Core = %Core
  31. // CHECK:STDOUT: .F = %F.decl
  32. // CHECK:STDOUT: .Run = %Run.decl
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  35. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  36. // CHECK:STDOUT: %Run.decl: %Run.type = fn_decl @Run [template = constants.%Run] {}
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: fn @F() {
  40. // CHECK:STDOUT: !entry:
  41. // CHECK:STDOUT: return
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: fn @Run() {
  45. // CHECK:STDOUT: !entry:
  46. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  47. // CHECK:STDOUT: %F.call: init %.1 = call %F.ref()
  48. // CHECK:STDOUT: %.loc17_7: i32 = int_literal 0 [template = constants.%.2]
  49. // CHECK:STDOUT: %.loc17_4.1: ref %.1 = temporary_storage
  50. // CHECK:STDOUT: %.loc17_4.2: ref %.1 = temporary %.loc17_4.1, %F.call
  51. // CHECK:STDOUT: %.loc17_8: ref <error> = tuple_index %.loc17_4.2, <error>
  52. // CHECK:STDOUT: return
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: