fail_invalid_base.carbon 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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+4]]:14: error: type `type` does not support indexing [TypeNotIndexable]
  28. // CHECK:STDERR: var d: i32 = {.a: i32, .b: i32}[0];
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~~~~~
  30. // CHECK:STDERR:
  31. var d: i32 = {.a: i32, .b: i32}[0];
  32. // CHECK:STDOUT: --- fail_invalid_base.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  36. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  37. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  38. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  39. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  40. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  41. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
  42. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  43. // CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1, %int_2) [template]
  44. // CHECK:STDOUT: %struct_type.a.b.501: type = struct_type {.a: %i32, .b: %i32} [template]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: imports {
  48. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  49. // CHECK:STDOUT: .Int = %Core.Int
  50. // CHECK:STDOUT: .IndexWith = %Core.IndexWith
  51. // CHECK:STDOUT: import Core//prelude
  52. // CHECK:STDOUT: import Core//prelude/...
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: file {
  57. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  58. // CHECK:STDOUT: .Core = imports.%Core
  59. // CHECK:STDOUT: .N = %N
  60. // CHECK:STDOUT: .a = %a
  61. // CHECK:STDOUT: .F = %F.decl
  62. // CHECK:STDOUT: .b = %b
  63. // CHECK:STDOUT: .c = %c
  64. // CHECK:STDOUT: .d = %d
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: %Core.import = import Core
  67. // CHECK:STDOUT: %N: <namespace> = namespace [template] {}
  68. // CHECK:STDOUT: name_binding_decl {
  69. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  70. // CHECK:STDOUT: %.loc16_1: %i32 = var_pattern %a.patt
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: %a.var: ref %i32 = var a
  73. // CHECK:STDOUT: %.loc16_8: type = splice_block %i32.loc16 [template = constants.%i32] {
  74. // CHECK:STDOUT: %int_32.loc16: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  75. // CHECK:STDOUT: %i32.loc16: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  78. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  79. // CHECK:STDOUT: name_binding_decl {
  80. // CHECK:STDOUT: %b.patt: %i32 = binding_pattern b
  81. // CHECK:STDOUT: %.loc23_1: %i32 = var_pattern %b.patt
  82. // CHECK:STDOUT: }
  83. // CHECK:STDOUT: %b.var: ref %i32 = var b
  84. // CHECK:STDOUT: %.loc23_8: type = splice_block %i32.loc23 [template = constants.%i32] {
  85. // CHECK:STDOUT: %int_32.loc23: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  86. // CHECK:STDOUT: %i32.loc23: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  89. // CHECK:STDOUT: name_binding_decl {
  90. // CHECK:STDOUT: %c.patt: %i32 = binding_pattern c
  91. // CHECK:STDOUT: %.loc29_1: %i32 = var_pattern %c.patt
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT: %c.var: ref %i32 = var c
  94. // CHECK:STDOUT: %.loc29_8: type = splice_block %i32.loc29 [template = constants.%i32] {
  95. // CHECK:STDOUT: %int_32.loc29: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  96. // CHECK:STDOUT: %i32.loc29: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  97. // CHECK:STDOUT: }
  98. // CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
  99. // CHECK:STDOUT: name_binding_decl {
  100. // CHECK:STDOUT: %d.patt: %i32 = binding_pattern d
  101. // CHECK:STDOUT: %.loc35_1: %i32 = var_pattern %d.patt
  102. // CHECK:STDOUT: }
  103. // CHECK:STDOUT: %d.var: ref %i32 = var d
  104. // CHECK:STDOUT: %.loc35_8: type = splice_block %i32.loc35 [template = constants.%i32] {
  105. // CHECK:STDOUT: %int_32.loc35: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  106. // CHECK:STDOUT: %i32.loc35: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  107. // CHECK:STDOUT: }
  108. // CHECK:STDOUT: %d: ref %i32 = bind_name d, %d.var
  109. // CHECK:STDOUT: }
  110. // CHECK:STDOUT:
  111. // CHECK:STDOUT: fn @F();
  112. // CHECK:STDOUT:
  113. // CHECK:STDOUT: fn @__global_init() {
  114. // CHECK:STDOUT: !entry:
  115. // CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
  116. // CHECK:STDOUT: %int_0.loc16: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  117. // CHECK:STDOUT: assign file.%a.var, <error>
  118. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  119. // CHECK:STDOUT: %int_1.loc23: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  120. // CHECK:STDOUT: assign file.%b.var, <error>
  121. // CHECK:STDOUT: %int_1.loc29: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  122. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2]
  123. // CHECK:STDOUT: %.loc29_29.1: %struct_type.a.b.cfd = struct_literal (%int_1.loc29, %int_2)
  124. // CHECK:STDOUT: %int_0.loc29: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  125. // CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1.loc29, %int_2) [template = constants.%struct]
  126. // CHECK:STDOUT: %.loc29_29.2: %struct_type.a.b.cfd = converted %.loc29_29.1, %struct [template = constants.%struct]
  127. // CHECK:STDOUT: assign file.%c.var, <error>
  128. // CHECK:STDOUT: %int_32.loc35_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  129. // CHECK:STDOUT: %i32.loc35_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  130. // CHECK:STDOUT: %int_32.loc35_28: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  131. // CHECK:STDOUT: %i32.loc35_28: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  132. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [template = constants.%struct_type.a.b.501]
  133. // CHECK:STDOUT: %int_0.loc35: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  134. // CHECK:STDOUT: assign file.%d.var, <error>
  135. // CHECK:STDOUT: return
  136. // CHECK:STDOUT: }
  137. // CHECK:STDOUT: