fail_invalid_base.carbon 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 [UseOfNonExprAsValue]
  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 [UseOfNonExprAsValue]
  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: Core.IntLiteral, .b: Core.IntLiteral}` does not support indexing [TypeNotIndexable]
  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 [TypeNotIndexable]
  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: %.1: Core.IntLiteral = int_value 32 [template]
  35. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  36. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  37. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  38. // CHECK:STDOUT: %.2: Core.IntLiteral = int_value 0 [template]
  39. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  40. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  41. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 1 [template]
  42. // CHECK:STDOUT: %.4: Core.IntLiteral = int_value 2 [template]
  43. // CHECK:STDOUT: %.5: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  44. // CHECK:STDOUT: %struct: %.5 = struct_value (%.3, %.4) [template]
  45. // CHECK:STDOUT: %.9: type = struct_type {.a: %i32, .b: %i32} [template]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: imports {
  49. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  50. // CHECK:STDOUT: .Int = %import_ref.1
  51. // CHECK:STDOUT: .IndexWith = %import_ref.2
  52. // CHECK:STDOUT: import Core//prelude
  53. // CHECK:STDOUT: import Core//prelude/...
  54. // CHECK:STDOUT: }
  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: .N = %N
  61. // CHECK:STDOUT: .a = %a
  62. // CHECK:STDOUT: .F = %F.decl
  63. // CHECK:STDOUT: .b = %b
  64. // CHECK:STDOUT: .c = %c
  65. // CHECK:STDOUT: .d = %d
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %N: <namespace> = namespace [template] {}
  69. // CHECK:STDOUT: %.loc16_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  70. // CHECK:STDOUT: %int.make_type_signed.loc16: init type = call constants.%Int(%.loc16_8.1) [template = constants.%i32]
  71. // CHECK:STDOUT: %.loc16_8.2: type = value_of_initializer %int.make_type_signed.loc16 [template = constants.%i32]
  72. // CHECK:STDOUT: %.loc16_8.3: type = converted %int.make_type_signed.loc16, %.loc16_8.2 [template = constants.%i32]
  73. // CHECK:STDOUT: %a.var: ref %i32 = var a
  74. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  75. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  76. // CHECK:STDOUT: %.loc23_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  77. // CHECK:STDOUT: %int.make_type_signed.loc23: init type = call constants.%Int(%.loc23_8.1) [template = constants.%i32]
  78. // CHECK:STDOUT: %.loc23_8.2: type = value_of_initializer %int.make_type_signed.loc23 [template = constants.%i32]
  79. // CHECK:STDOUT: %.loc23_8.3: type = converted %int.make_type_signed.loc23, %.loc23_8.2 [template = constants.%i32]
  80. // CHECK:STDOUT: %b.var: ref %i32 = var b
  81. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  82. // CHECK:STDOUT: %.loc29_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  83. // CHECK:STDOUT: %int.make_type_signed.loc29: init type = call constants.%Int(%.loc29_8.1) [template = constants.%i32]
  84. // CHECK:STDOUT: %.loc29_8.2: type = value_of_initializer %int.make_type_signed.loc29 [template = constants.%i32]
  85. // CHECK:STDOUT: %.loc29_8.3: type = converted %int.make_type_signed.loc29, %.loc29_8.2 [template = constants.%i32]
  86. // CHECK:STDOUT: %c.var: ref %i32 = var c
  87. // CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
  88. // CHECK:STDOUT: %.loc34_8.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  89. // CHECK:STDOUT: %int.make_type_signed.loc34: init type = call constants.%Int(%.loc34_8.1) [template = constants.%i32]
  90. // CHECK:STDOUT: %.loc34_8.2: type = value_of_initializer %int.make_type_signed.loc34 [template = constants.%i32]
  91. // CHECK:STDOUT: %.loc34_8.3: type = converted %int.make_type_signed.loc34, %.loc34_8.2 [template = constants.%i32]
  92. // CHECK:STDOUT: %d.var: ref %i32 = var d
  93. // CHECK:STDOUT: %d: ref %i32 = bind_name d, %d.var
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT:
  96. // CHECK:STDOUT: fn @F();
  97. // CHECK:STDOUT:
  98. // CHECK:STDOUT: fn @__global_init() {
  99. // CHECK:STDOUT: !entry:
  100. // CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
  101. // CHECK:STDOUT: %.loc16: Core.IntLiteral = int_value 0 [template = constants.%.2]
  102. // CHECK:STDOUT: assign file.%a.var, <error>
  103. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  104. // CHECK:STDOUT: %.loc23: Core.IntLiteral = int_value 1 [template = constants.%.3]
  105. // CHECK:STDOUT: assign file.%b.var, <error>
  106. // CHECK:STDOUT: %.loc29_20: Core.IntLiteral = int_value 1 [template = constants.%.3]
  107. // CHECK:STDOUT: %.loc29_28: Core.IntLiteral = int_value 2 [template = constants.%.4]
  108. // CHECK:STDOUT: %.loc29_29.1: %.5 = struct_literal (%.loc29_20, %.loc29_28)
  109. // CHECK:STDOUT: %.loc29_31: Core.IntLiteral = int_value 0 [template = constants.%.2]
  110. // CHECK:STDOUT: %struct: %.5 = struct_value (%.loc29_20, %.loc29_28) [template = constants.%struct]
  111. // CHECK:STDOUT: %.loc29_29.2: %.5 = converted %.loc29_29.1, %struct [template = constants.%struct]
  112. // CHECK:STDOUT: assign file.%c.var, <error>
  113. // CHECK:STDOUT: %.loc34_19.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  114. // CHECK:STDOUT: %int.make_type_signed.loc34_19: init type = call constants.%Int(%.loc34_19.1) [template = constants.%i32]
  115. // CHECK:STDOUT: %.loc34_19.2: type = value_of_initializer %int.make_type_signed.loc34_19 [template = constants.%i32]
  116. // CHECK:STDOUT: %.loc34_19.3: type = converted %int.make_type_signed.loc34_19, %.loc34_19.2 [template = constants.%i32]
  117. // CHECK:STDOUT: %.loc34_28.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  118. // CHECK:STDOUT: %int.make_type_signed.loc34_28: init type = call constants.%Int(%.loc34_28.1) [template = constants.%i32]
  119. // CHECK:STDOUT: %.loc34_28.2: type = value_of_initializer %int.make_type_signed.loc34_28 [template = constants.%i32]
  120. // CHECK:STDOUT: %.loc34_28.3: type = converted %int.make_type_signed.loc34_28, %.loc34_28.2 [template = constants.%i32]
  121. // CHECK:STDOUT: %.loc34_31: type = struct_type {.a: %i32, .b: %i32} [template = constants.%.9]
  122. // CHECK:STDOUT: %.loc34_33: Core.IntLiteral = int_value 0 [template = constants.%.2]
  123. // CHECK:STDOUT: assign file.%d.var, <error>
  124. // CHECK:STDOUT: return
  125. // CHECK:STDOUT: }
  126. // CHECK:STDOUT: