fail_invalid_base.carbon 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  49. // CHECK:STDOUT: .Core = %Core
  50. // CHECK:STDOUT: .N = %N
  51. // CHECK:STDOUT: .a = %a
  52. // CHECK:STDOUT: .F = %F.decl
  53. // CHECK:STDOUT: .b = %b
  54. // CHECK:STDOUT: .c = %c
  55. // CHECK:STDOUT: .d = %d
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  58. // CHECK:STDOUT: %N: <namespace> = namespace [template] {}
  59. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  60. // CHECK:STDOUT: %int.make_type_32.loc16: init type = call constants.%Int32() [template = i32]
  61. // CHECK:STDOUT: %.loc16_8.1: type = value_of_initializer %int.make_type_32.loc16 [template = i32]
  62. // CHECK:STDOUT: %.loc16_8.2: type = converted %int.make_type_32.loc16, %.loc16_8.1 [template = i32]
  63. // CHECK:STDOUT: %a.var: ref i32 = var a
  64. // CHECK:STDOUT: %a: ref i32 = bind_name a, %a.var
  65. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {}
  66. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  67. // CHECK:STDOUT: %int.make_type_32.loc23: init type = call constants.%Int32() [template = i32]
  68. // CHECK:STDOUT: %.loc23_8.1: type = value_of_initializer %int.make_type_32.loc23 [template = i32]
  69. // CHECK:STDOUT: %.loc23_8.2: type = converted %int.make_type_32.loc23, %.loc23_8.1 [template = i32]
  70. // CHECK:STDOUT: %b.var: ref i32 = var b
  71. // CHECK:STDOUT: %b: ref i32 = bind_name b, %b.var
  72. // CHECK:STDOUT: %import_ref.3: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  73. // CHECK:STDOUT: %int.make_type_32.loc29: init type = call constants.%Int32() [template = i32]
  74. // CHECK:STDOUT: %.loc29_8.1: type = value_of_initializer %int.make_type_32.loc29 [template = i32]
  75. // CHECK:STDOUT: %.loc29_8.2: type = converted %int.make_type_32.loc29, %.loc29_8.1 [template = i32]
  76. // CHECK:STDOUT: %c.var: ref i32 = var c
  77. // CHECK:STDOUT: %c: ref i32 = bind_name c, %c.var
  78. // CHECK:STDOUT: %import_ref.4: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  79. // CHECK:STDOUT: %int.make_type_32.loc34: init type = call constants.%Int32() [template = i32]
  80. // CHECK:STDOUT: %.loc34_8.1: type = value_of_initializer %int.make_type_32.loc34 [template = i32]
  81. // CHECK:STDOUT: %.loc34_8.2: type = converted %int.make_type_32.loc34, %.loc34_8.1 [template = i32]
  82. // CHECK:STDOUT: %d.var: ref i32 = var d
  83. // CHECK:STDOUT: %d: ref i32 = bind_name d, %d.var
  84. // CHECK:STDOUT: %import_ref.5: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  85. // CHECK:STDOUT: %import_ref.6: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  86. // CHECK:STDOUT: }
  87. // CHECK:STDOUT:
  88. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @F();
  91. // CHECK:STDOUT:
  92. // CHECK:STDOUT: fn @__global_init() {
  93. // CHECK:STDOUT: !entry:
  94. // CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
  95. // CHECK:STDOUT: %.loc16: i32 = int_literal 0 [template = constants.%.2]
  96. // CHECK:STDOUT: assign file.%a.var, <error>
  97. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  98. // CHECK:STDOUT: %.loc23: i32 = int_literal 1 [template = constants.%.3]
  99. // CHECK:STDOUT: assign file.%b.var, <error>
  100. // CHECK:STDOUT: %.loc29_20: i32 = int_literal 1 [template = constants.%.3]
  101. // CHECK:STDOUT: %.loc29_28: i32 = int_literal 2 [template = constants.%.4]
  102. // CHECK:STDOUT: %.loc29_29.1: %.5 = struct_literal (%.loc29_20, %.loc29_28)
  103. // CHECK:STDOUT: %.loc29_31: i32 = int_literal 0 [template = constants.%.2]
  104. // CHECK:STDOUT: %struct: %.5 = struct_value (%.loc29_20, %.loc29_28) [template = constants.%struct]
  105. // CHECK:STDOUT: %.loc29_29.2: %.5 = converted %.loc29_29.1, %struct [template = constants.%struct]
  106. // CHECK:STDOUT: assign file.%c.var, <error>
  107. // CHECK:STDOUT: %int.make_type_32.loc34_19: init type = call constants.%Int32() [template = i32]
  108. // CHECK:STDOUT: %.loc34_19.1: type = value_of_initializer %int.make_type_32.loc34_19 [template = i32]
  109. // CHECK:STDOUT: %.loc34_19.2: type = converted %int.make_type_32.loc34_19, %.loc34_19.1 [template = i32]
  110. // CHECK:STDOUT: %int.make_type_32.loc34_28: init type = call constants.%Int32() [template = i32]
  111. // CHECK:STDOUT: %.loc34_28.1: type = value_of_initializer %int.make_type_32.loc34_28 [template = i32]
  112. // CHECK:STDOUT: %.loc34_28.2: type = converted %int.make_type_32.loc34_28, %.loc34_28.1 [template = i32]
  113. // CHECK:STDOUT: %.loc34_31: type = struct_type {.a: i32, .b: i32} [template = constants.%.5]
  114. // CHECK:STDOUT: %.loc34_33: i32 = int_literal 0 [template = constants.%.2]
  115. // CHECK:STDOUT: assign file.%d.var, <error>
  116. // CHECK:STDOUT: return
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: