fail_negative_indexing.carbon 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/tuple/access/fail_negative_indexing.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/tuple/access/fail_negative_indexing.carbon
  10. var a: (i32, i32) = (12, 6);
  11. // CHECK:STDERR: fail_negative_indexing.carbon:[[@LINE+3]]:17: error: cannot access member of interface `Negate` in type `i32` that does not implement that interface
  12. // CHECK:STDERR: var b: i32 = a.(-10);
  13. // CHECK:STDERR: ^~~
  14. var b: i32 = a.(-10);
  15. // CHECK:STDOUT: --- fail_negative_indexing.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %.2: type = tuple_type (type, type) [template]
  22. // CHECK:STDOUT: %.3: type = tuple_type (i32, i32) [template]
  23. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  24. // CHECK:STDOUT: %.5: i32 = int_literal 12 [template]
  25. // CHECK:STDOUT: %.6: i32 = int_literal 6 [template]
  26. // CHECK:STDOUT: %tuple: %.3 = tuple_value (%.5, %.6) [template]
  27. // CHECK:STDOUT: %.7: i32 = int_literal 10 [template]
  28. // CHECK:STDOUT: %.8: type = interface_type @Negate [template]
  29. // CHECK:STDOUT: %Self: %.8 = bind_symbolic_name Self 0 [symbolic]
  30. // CHECK:STDOUT: %Op.type: type = fn_type @Op [template]
  31. // CHECK:STDOUT: %Op: %Op.type = struct_value () [template]
  32. // CHECK:STDOUT: %.9: type = assoc_entity_type %.8, %Op.type [template]
  33. // CHECK:STDOUT: %.10: %.9 = assoc_entity element0, imports.%import_ref.6 [template]
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: imports {
  37. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  38. // CHECK:STDOUT: .Int32 = %import_ref.1
  39. // CHECK:STDOUT: .Negate = %import_ref.2
  40. // CHECK:STDOUT: import Core//prelude
  41. // CHECK:STDOUT: import Core//prelude/operators
  42. // CHECK:STDOUT: import Core//prelude/types
  43. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  44. // CHECK:STDOUT: import Core//prelude/operators/as
  45. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  46. // CHECK:STDOUT: import Core//prelude/operators/comparison
  47. // CHECK:STDOUT: import Core//prelude/types/bool
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  50. // CHECK:STDOUT: %import_ref.2: type = import_ref Core//prelude/operators/arithmetic, inst+77, loaded [template = constants.%.8]
  51. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/arithmetic, inst+79, unloaded
  52. // CHECK:STDOUT: %import_ref.4: %.9 = import_ref Core//prelude/operators/arithmetic, inst+96, loaded [template = constants.%.10]
  53. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/arithmetic, inst+91, unloaded
  54. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/arithmetic, inst+91, unloaded
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: file {
  58. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  59. // CHECK:STDOUT: .Core = imports.%Core
  60. // CHECK:STDOUT: .a = %a
  61. // CHECK:STDOUT: .b = %b
  62. // CHECK:STDOUT: }
  63. // CHECK:STDOUT: %Core.import = import Core
  64. // CHECK:STDOUT: %int.make_type_32.loc11_9: init type = call constants.%Int32() [template = i32]
  65. // CHECK:STDOUT: %int.make_type_32.loc11_14: init type = call constants.%Int32() [template = i32]
  66. // CHECK:STDOUT: %.loc11_17.1: %.2 = tuple_literal (%int.make_type_32.loc11_9, %int.make_type_32.loc11_14)
  67. // CHECK:STDOUT: %.loc11_17.2: type = value_of_initializer %int.make_type_32.loc11_9 [template = i32]
  68. // CHECK:STDOUT: %.loc11_17.3: type = converted %int.make_type_32.loc11_9, %.loc11_17.2 [template = i32]
  69. // CHECK:STDOUT: %.loc11_17.4: type = value_of_initializer %int.make_type_32.loc11_14 [template = i32]
  70. // CHECK:STDOUT: %.loc11_17.5: type = converted %int.make_type_32.loc11_14, %.loc11_17.4 [template = i32]
  71. // CHECK:STDOUT: %.loc11_17.6: type = converted %.loc11_17.1, constants.%.3 [template = constants.%.3]
  72. // CHECK:STDOUT: %a.var: ref %.3 = var a
  73. // CHECK:STDOUT: %a: ref %.3 = bind_name a, %a.var
  74. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  75. // CHECK:STDOUT: %.loc15_8.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  76. // CHECK:STDOUT: %.loc15_8.2: type = converted %int.make_type_32.loc15, %.loc15_8.1 [template = i32]
  77. // CHECK:STDOUT: %b.var: ref i32 = var b
  78. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT:
  81. // CHECK:STDOUT: interface @Negate {
  82. // CHECK:STDOUT: !members:
  83. // CHECK:STDOUT: .Self = imports.%import_ref.3
  84. // CHECK:STDOUT: .Op = imports.%import_ref.4
  85. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: generic fn @Op(constants.%Self: %.8) {
  91. // CHECK:STDOUT: %Self: %.8 = bind_symbolic_name Self 0 [symbolic = %Self (constants.%Self)]
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn[%self: @Op.%Self (%Self)]() -> @Op.%Self (%Self);
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @__global_init() {
  97. // CHECK:STDOUT: !entry:
  98. // CHECK:STDOUT: %.loc11_22: i32 = int_literal 12 [template = constants.%.5]
  99. // CHECK:STDOUT: %.loc11_26: i32 = int_literal 6 [template = constants.%.6]
  100. // CHECK:STDOUT: %.loc11_27.1: %.3 = tuple_literal (%.loc11_22, %.loc11_26)
  101. // CHECK:STDOUT: %.loc11_27.2: ref i32 = tuple_access file.%a.var, element0
  102. // CHECK:STDOUT: %.loc11_27.3: init i32 = initialize_from %.loc11_22 to %.loc11_27.2 [template = constants.%.5]
  103. // CHECK:STDOUT: %.loc11_27.4: ref i32 = tuple_access file.%a.var, element1
  104. // CHECK:STDOUT: %.loc11_27.5: init i32 = initialize_from %.loc11_26 to %.loc11_27.4 [template = constants.%.6]
  105. // CHECK:STDOUT: %.loc11_27.6: init %.3 = tuple_init (%.loc11_27.3, %.loc11_27.5) to file.%a.var [template = constants.%tuple]
  106. // CHECK:STDOUT: %.loc11_28: init %.3 = converted %.loc11_27.1, %.loc11_27.6 [template = constants.%tuple]
  107. // CHECK:STDOUT: assign file.%a.var, %.loc11_28
  108. // CHECK:STDOUT: %a.ref: ref %.3 = name_ref a, file.%a
  109. // CHECK:STDOUT: %.loc15: i32 = int_literal 10 [template = constants.%.7]
  110. // CHECK:STDOUT: %Op.ref: %.9 = name_ref Op, imports.%import_ref.4 [template = constants.%.10]
  111. // CHECK:STDOUT: assign file.%b.var, <error>
  112. // CHECK:STDOUT: return
  113. // CHECK:STDOUT: }
  114. // CHECK:STDOUT:
  115. // CHECK:STDOUT: specific @Op(constants.%Self) {
  116. // CHECK:STDOUT: %Self => constants.%Self
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: