fail_non_tuple_access.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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_non_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_non_tuple_access.carbon
  10. fn Main() {
  11. // CHECK:STDERR: fail_non_tuple_access.carbon:[[@LINE+3]]:3: error: type `i32` does not support indexing [TypeNotIndexable]
  12. // CHECK:STDERR: 0[1];
  13. // CHECK:STDERR: ^~~~
  14. 0[1];
  15. }
  16. // CHECK:STDOUT: --- fail_non_tuple_access.carbon
  17. // CHECK:STDOUT:
  18. // CHECK:STDOUT: constants {
  19. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  20. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  21. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  22. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  23. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  24. // CHECK:STDOUT: %IndexWith.type.1: type = generic_interface_type @IndexWith [template]
  25. // CHECK:STDOUT: %IndexWith: %IndexWith.type.1 = struct_value () [template]
  26. // CHECK:STDOUT: %ElementType: type = bind_symbolic_name ElementType, 1 [symbolic]
  27. // CHECK:STDOUT: %SubscriptType: type = bind_symbolic_name SubscriptType, 0 [symbolic]
  28. // CHECK:STDOUT: %IndexWith.type.2: type = interface_type @IndexWith, @IndexWith(%SubscriptType, %ElementType) [symbolic]
  29. // CHECK:STDOUT: %Self.1: @IndexWith.%IndexWith.type (%IndexWith.type.2) = bind_symbolic_name Self, 2 [symbolic]
  30. // CHECK:STDOUT: %ElementType.patt: type = symbolic_binding_pattern ElementType, 1 [symbolic]
  31. // CHECK:STDOUT: %SubscriptType.patt: type = symbolic_binding_pattern SubscriptType, 0 [symbolic]
  32. // CHECK:STDOUT: %Self.2: %IndexWith.type.2 = bind_symbolic_name Self, 2 [symbolic]
  33. // CHECK:STDOUT: %At.type: type = fn_type @At, @IndexWith(%SubscriptType, %ElementType) [symbolic]
  34. // CHECK:STDOUT: %At: %At.type = struct_value () [symbolic]
  35. // CHECK:STDOUT: %.4: type = assoc_entity_type %IndexWith.type.2, %At.type [symbolic]
  36. // CHECK:STDOUT: %.5: %.4 = assoc_entity element0, imports.%import_ref.5 [symbolic]
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: imports {
  40. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  41. // CHECK:STDOUT: .IndexWith = %import_ref.1
  42. // CHECK:STDOUT: import Core//prelude
  43. // CHECK:STDOUT: import Core//prelude/...
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %import_ref.1: %IndexWith.type.1 = import_ref Core//prelude/operators/index, inst+13, loaded [template = constants.%IndexWith]
  46. // CHECK:STDOUT: %import_ref.2 = import_ref Core//prelude/operators/index, inst+22, unloaded
  47. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/index, inst+50, unloaded
  48. // CHECK:STDOUT: %import_ref.4 = import_ref Core//prelude/operators/index, inst+42, unloaded
  49. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/index, inst+42, unloaded
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  54. // CHECK:STDOUT: .Core = imports.%Core
  55. // CHECK:STDOUT: .Main = %Main.decl
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core.import = import Core
  58. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: generic interface @IndexWith(constants.%SubscriptType: type, constants.%ElementType: type) {
  62. // CHECK:STDOUT: %SubscriptType: type = bind_symbolic_name SubscriptType, 0 [symbolic = %SubscriptType (constants.%SubscriptType)]
  63. // CHECK:STDOUT: %SubscriptType.patt: type = symbolic_binding_pattern SubscriptType, 0 [symbolic = %SubscriptType.patt (constants.%SubscriptType.patt)]
  64. // CHECK:STDOUT: %ElementType: type = bind_symbolic_name ElementType, 1 [symbolic = %ElementType (constants.%ElementType)]
  65. // CHECK:STDOUT: %ElementType.patt: type = symbolic_binding_pattern ElementType, 1 [symbolic = %ElementType.patt (constants.%ElementType.patt)]
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: !definition:
  68. // CHECK:STDOUT: %IndexWith.type: type = interface_type @IndexWith, @IndexWith(%SubscriptType, %ElementType) [symbolic = %IndexWith.type (constants.%IndexWith.type.2)]
  69. // CHECK:STDOUT: %Self: %IndexWith.type.2 = bind_symbolic_name Self, 2 [symbolic = %Self (constants.%Self.2)]
  70. // CHECK:STDOUT: %At.type: type = fn_type @At, @IndexWith(%SubscriptType, %ElementType) [symbolic = %At.type (constants.%At.type)]
  71. // CHECK:STDOUT: %At: @IndexWith.%At.type (%At.type) = struct_value () [symbolic = %At (constants.%At)]
  72. // CHECK:STDOUT: %.1: type = assoc_entity_type @IndexWith.%IndexWith.type (%IndexWith.type.2), @IndexWith.%At.type (%At.type) [symbolic = %.1 (constants.%.4)]
  73. // CHECK:STDOUT: %.2: @IndexWith.%.1 (%.4) = assoc_entity element0, imports.%import_ref.5 [symbolic = %.2 (constants.%.5)]
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: interface {
  76. // CHECK:STDOUT: !members:
  77. // CHECK:STDOUT: .Self = imports.%import_ref.2
  78. // CHECK:STDOUT: .At = imports.%import_ref.3
  79. // CHECK:STDOUT: witness = (imports.%import_ref.4)
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @Main() {
  84. // CHECK:STDOUT: !entry:
  85. // CHECK:STDOUT: %.loc15_3: i32 = int_literal 0 [template = constants.%.2]
  86. // CHECK:STDOUT: %.loc15_5: i32 = int_literal 1 [template = constants.%.3]
  87. // CHECK:STDOUT: return
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: generic fn @At(constants.%SubscriptType: type, constants.%ElementType: type, constants.%Self.1: @IndexWith.%IndexWith.type (%IndexWith.type.2)) {
  91. // CHECK:STDOUT: %SubscriptType: type = bind_symbolic_name SubscriptType, 0 [symbolic = %SubscriptType (constants.%SubscriptType)]
  92. // CHECK:STDOUT: %ElementType: type = bind_symbolic_name ElementType, 1 [symbolic = %ElementType (constants.%ElementType)]
  93. // CHECK:STDOUT: %IndexWith.type: type = interface_type @IndexWith, @IndexWith(%SubscriptType, %ElementType) [symbolic = %IndexWith.type (constants.%IndexWith.type.2)]
  94. // CHECK:STDOUT: %Self: %IndexWith.type.2 = bind_symbolic_name Self, 2 [symbolic = %Self (constants.%Self.2)]
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn[%self.param_patt: @At.%Self (%Self.2)](%subscript.param_patt: @At.%SubscriptType (%SubscriptType)) -> @At.%ElementType (%ElementType);
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: specific @IndexWith(constants.%SubscriptType, constants.%ElementType) {
  100. // CHECK:STDOUT: %SubscriptType => constants.%SubscriptType
  101. // CHECK:STDOUT: %SubscriptType.patt => constants.%SubscriptType
  102. // CHECK:STDOUT: %ElementType => constants.%ElementType
  103. // CHECK:STDOUT: %ElementType.patt => constants.%ElementType
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: specific @IndexWith(@IndexWith.%SubscriptType, @IndexWith.%ElementType) {
  107. // CHECK:STDOUT: %SubscriptType => constants.%SubscriptType
  108. // CHECK:STDOUT: %SubscriptType.patt => constants.%SubscriptType
  109. // CHECK:STDOUT: %ElementType => constants.%ElementType
  110. // CHECK:STDOUT: %ElementType.patt => constants.%ElementType
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: specific @IndexWith(@At.%SubscriptType, @At.%ElementType) {
  114. // CHECK:STDOUT: %SubscriptType => constants.%SubscriptType
  115. // CHECK:STDOUT: %SubscriptType.patt => constants.%SubscriptType
  116. // CHECK:STDOUT: %ElementType => constants.%ElementType
  117. // CHECK:STDOUT: %ElementType.patt => constants.%ElementType
  118. // CHECK:STDOUT: }
  119. // CHECK:STDOUT:
  120. // CHECK:STDOUT: specific @At(constants.%SubscriptType, constants.%ElementType, constants.%Self.1) {
  121. // CHECK:STDOUT: %SubscriptType => constants.%SubscriptType
  122. // CHECK:STDOUT: %ElementType => constants.%ElementType
  123. // CHECK:STDOUT: %IndexWith.type => constants.%IndexWith.type.2
  124. // CHECK:STDOUT: %Self => constants.%Self.1
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: