fail_invalid_base.carbon 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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: %int_32: Core.IntLiteral = int_value 32 [template]
  35. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  36. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template]
  37. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  38. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  39. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  40. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template]
  41. // CHECK:STDOUT: %struct_type.a.b.cfd: type = struct_type {.a: Core.IntLiteral, .b: Core.IntLiteral} [template]
  42. // CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1, %int_2) [template]
  43. // CHECK:STDOUT: %struct_type.a.b.3de: type = struct_type {.a: %i32, .b: %i32} [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: .Int = %import_ref.187
  49. // CHECK:STDOUT: .IndexWith = %import_ref.76d
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .N = %N
  59. // CHECK:STDOUT: .a = %a
  60. // CHECK:STDOUT: .F = %F.decl
  61. // CHECK:STDOUT: .b = %b
  62. // CHECK:STDOUT: .c = %c
  63. // CHECK:STDOUT: .d = %d
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %Core.import = import Core
  66. // CHECK:STDOUT: %N: <namespace> = namespace [template] {}
  67. // CHECK:STDOUT: %a.var: ref %i32 = var a
  68. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  69. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
  70. // CHECK:STDOUT: %b.var: ref %i32 = var b
  71. // CHECK:STDOUT: %b: ref %i32 = bind_name b, %b.var
  72. // CHECK:STDOUT: %c.var: ref %i32 = var c
  73. // CHECK:STDOUT: %c: ref %i32 = bind_name c, %c.var
  74. // CHECK:STDOUT: %d.var: ref %i32 = var d
  75. // CHECK:STDOUT: %d: ref %i32 = bind_name d, %d.var
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT:
  78. // CHECK:STDOUT: fn @F();
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @__global_init() {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %N.ref: <namespace> = name_ref N, file.%N [template = file.%N]
  83. // CHECK:STDOUT: %int_0.loc16: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  84. // CHECK:STDOUT: assign file.%a.var, <error>
  85. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  86. // CHECK:STDOUT: %int_1.loc23: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  87. // CHECK:STDOUT: assign file.%b.var, <error>
  88. // CHECK:STDOUT: %int_1.loc29: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  89. // CHECK:STDOUT: %int_2: Core.IntLiteral = int_value 2 [template = constants.%int_2]
  90. // CHECK:STDOUT: %.loc29_29.1: %struct_type.a.b.cfd = struct_literal (%int_1.loc29, %int_2)
  91. // CHECK:STDOUT: %int_0.loc29: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  92. // CHECK:STDOUT: %struct: %struct_type.a.b.cfd = struct_value (%int_1.loc29, %int_2) [template = constants.%struct]
  93. // CHECK:STDOUT: %.loc29_29.2: %struct_type.a.b.cfd = converted %.loc29_29.1, %struct [template = constants.%struct]
  94. // CHECK:STDOUT: assign file.%c.var, <error>
  95. // CHECK:STDOUT: %int_32.loc34_19: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  96. // CHECK:STDOUT: %i32.loc34_19: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  97. // CHECK:STDOUT: %int_32.loc34_28: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  98. // CHECK:STDOUT: %i32.loc34_28: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  99. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [template = constants.%struct_type.a.b.3de]
  100. // CHECK:STDOUT: %int_0.loc34: Core.IntLiteral = int_value 0 [template = constants.%int_0]
  101. // CHECK:STDOUT: assign file.%d.var, <error>
  102. // CHECK:STDOUT: return
  103. // CHECK:STDOUT: }
  104. // CHECK:STDOUT: