fail_invalid_base.carbon 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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_invalid_base.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/index/fail_invalid_base.carbon
  10. namespace N;
  11. // CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: expression cannot be used as a value
  12. // CHECK:STDERR: var a: i32 = N[0];
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. var a: i32 = N[0];
  16. fn F();
  17. // CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: expression cannot be used as a value
  18. // CHECK:STDERR: var b: i32 = F[1];
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR:
  21. var b: i32 = F[1];
  22. // CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+4]]:14: error: type `{.a: i32, .b: i32}` does not support indexing
  23. // CHECK:STDERR: var c: i32 = {.a = 1, .b = 2}[0];
  24. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~
  25. // CHECK:STDERR:
  26. var c: i32 = {.a = 1, .b = 2}[0];
  27. // CHECK:STDERR: fail_invalid_base.carbon:[[@LINE+3]]:14: error: type `type` does not support indexing
  28. // CHECK:STDERR: var d: i32 = {.a: i32, .b: i32}[0];
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  30. var d: i32 = {.a: i32, .b: i32}[0];
  31. // CHECK:STDOUT: --- fail_invalid_base.carbon
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: constants {
  34. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  35. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  36. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  37. // CHECK:STDOUT: %.2: i32 = int_literal 0 [template]
  38. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  39. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  40. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  41. // CHECK:STDOUT: %.4: i32 = int_literal 2 [template]
  42. // CHECK:STDOUT: %.5: type = struct_type {.a: i32, .b: i32} [template]
  43. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  44. // CHECK:STDOUT: %struct: %.5 = struct_value (%.3, %.4) [template]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  49. // CHECK:STDOUT: .Int32 = %import_ref
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/operators
  52. // CHECK:STDOUT: import Core//prelude/types
  53. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  54. // CHECK:STDOUT: import Core//prelude/operators/as
  55. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  56. // CHECK:STDOUT: import Core//prelude/operators/comparison
  57. // CHECK:STDOUT: import Core//prelude/types/bool
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: file {
  63. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  64. // CHECK:STDOUT: .Core = imports.%Core
  65. // CHECK:STDOUT: .N = %N
  66. // CHECK:STDOUT: .a = %a
  67. // CHECK:STDOUT: .F = %F.decl
  68. // CHECK:STDOUT: .b = %b
  69. // CHECK:STDOUT: .c = %c
  70. // CHECK:STDOUT: .d = %d
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %Core.import = import Core
  73. // CHECK:STDOUT: %N: <namespace> = namespace [template] {}
  74. // CHECK:STDOUT: %int.make_type_32.loc16: init type = call constants.%Int32() [template = i32]
  75. // CHECK:STDOUT: %.loc16_8.1: type = value_of_initializer %int.make_type_32.loc16 [template = i32]
  76. // CHECK:STDOUT: %.loc16_8.2: type = converted %int.make_type_32.loc16, %.loc16_8.1 [template = i32]
  77. // CHECK:STDOUT: %a.var: ref i32 = var a
  78. // CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
  79. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  80. // CHECK:STDOUT: %int.make_type_32.loc23: init type = call constants.%Int32() [template = i32]
  81. // CHECK:STDOUT: %.loc23_8.1: type = value_of_initializer %int.make_type_32.loc23 [template = i32]
  82. // CHECK:STDOUT: %.loc23_8.2: type = converted %int.make_type_32.loc23, %.loc23_8.1 [template = i32]
  83. // CHECK:STDOUT: %b.var: ref i32 = var b
  84. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  85. // CHECK:STDOUT: %int.make_type_32.loc29: init type = call constants.%Int32() [template = i32]
  86. // CHECK:STDOUT: %.loc29_8.1: type = value_of_initializer %int.make_type_32.loc29 [template = i32]
  87. // CHECK:STDOUT: %.loc29_8.2: type = converted %int.make_type_32.loc29, %.loc29_8.1 [template = i32]
  88. // CHECK:STDOUT: %c.var: ref i32 = var c
  89. // CHECK:STDOUT: %c: ref i32 = bind_name c, %c.var
  90. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  91. // CHECK:STDOUT: %.loc34_8.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  92. // CHECK:STDOUT: %.loc34_8.2: type = converted %int.make_type_32.loc34, %.loc34_8.1 [template = i32]
  93. // CHECK:STDOUT: %d.var: ref i32 = var d
  94. // CHECK:STDOUT: %d: ref i32 = bind_name d, %d.var
  95. // CHECK:STDOUT: }
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  98. // CHECK:STDOUT:
  99. // CHECK:STDOUT: fn @F();
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @__global_init() {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
  104. // CHECK:STDOUT: %.loc16: i32 = int_literal 0 [template = constants.%.2]
  105. // CHECK:STDOUT: assign file.%a.var, <error>
  106. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  107. // CHECK:STDOUT: %.loc23: i32 = int_literal 1 [template = constants.%.3]
  108. // CHECK:STDOUT: assign file.%b.var, <error>
  109. // CHECK:STDOUT: %.loc29_20: i32 = int_literal 1 [template = constants.%.3]
  110. // CHECK:STDOUT: %.loc29_28: i32 = int_literal 2 [template = constants.%.4]
  111. // CHECK:STDOUT: %.loc29_29.1: %.5 = struct_literal (%.loc29_20, %.loc29_28)
  112. // CHECK:STDOUT: %.loc29_31: i32 = int_literal 0 [template = constants.%.2]
  113. // CHECK:STDOUT: %struct: %.5 = struct_value (%.loc29_20, %.loc29_28) [template = constants.%struct]
  114. // CHECK:STDOUT: %.loc29_29.2: %.5 = converted %.loc29_29.1, %struct [template = constants.%struct]
  115. // CHECK:STDOUT: assign file.%c.var, <error>
  116. // CHECK:STDOUT: %int.make_type_32.loc34_19: init type = call constants.%Int32() [template = i32]
  117. // CHECK:STDOUT: %.loc34_19.1: type = value_of_initializer %int.make_type_32.loc34_19 [template = i32]
  118. // CHECK:STDOUT: %.loc34_19.2: type = converted %int.make_type_32.loc34_19, %.loc34_19.1 [template = i32]
  119. // CHECK:STDOUT: %int.make_type_32.loc34_28: init type = call constants.%Int32() [template = i32]
  120. // CHECK:STDOUT: %.loc34_28.1: type = value_of_initializer %int.make_type_32.loc34_28 [template = i32]
  121. // CHECK:STDOUT: %.loc34_28.2: type = converted %int.make_type_32.loc34_28, %.loc34_28.1 [template = i32]
  122. // CHECK:STDOUT: %.loc34_31: type = struct_type {.a: i32, .b: i32} [template = constants.%.5]
  123. // CHECK:STDOUT: %.loc34_33: i32 = int_literal 0 [template = constants.%.2]
  124. // CHECK:STDOUT: assign file.%d.var, <error>
  125. // CHECK:STDOUT: return
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT: