fail_non_member_access.carbon 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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/struct/fail_non_member_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_non_member_access.carbon
  10. var x: {.a: i32} = {.a = 4};
  11. // CHECK:STDERR: fail_non_member_access.carbon:[[@LINE+3]]:14: ERROR: Type `{.a: i32}` does not have a member `b`.
  12. // CHECK:STDERR: var y: i32 = x.b;
  13. // CHECK:STDERR: ^~~
  14. var y: i32 = x.b;
  15. // CHECK:STDOUT: --- fail_non_member_access.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  19. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  20. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  21. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  22. // CHECK:STDOUT: %.3: i32 = int_literal 4 [template]
  23. // CHECK:STDOUT: %struct: %.2 = struct_value (%.3) [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: file {
  27. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  28. // CHECK:STDOUT: .Core = %Core
  29. // CHECK:STDOUT: .x = %x
  30. // CHECK:STDOUT: .y = %y
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  33. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  34. // CHECK:STDOUT: %int.make_type_32.loc11: init type = call constants.%Int32() [template = i32]
  35. // CHECK:STDOUT: %.loc11_13.1: type = value_of_initializer %int.make_type_32.loc11 [template = i32]
  36. // CHECK:STDOUT: %.loc11_13.2: type = converted %int.make_type_32.loc11, %.loc11_13.1 [template = i32]
  37. // CHECK:STDOUT: %.loc11_16: type = struct_type {.a: i32} [template = constants.%.2]
  38. // CHECK:STDOUT: %x.var: ref %.2 = var x
  39. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  40. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  41. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  42. // CHECK:STDOUT: %.loc15_8.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  43. // CHECK:STDOUT: %.loc15_8.2: type = converted %int.make_type_32.loc15, %.loc15_8.1 [template = i32]
  44. // CHECK:STDOUT: %y.var: ref i32 = var y
  45. // CHECK:STDOUT: %y: ref i32 = bind_name y, %y.var
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  49. // CHECK:STDOUT:
  50. // CHECK:STDOUT: fn @__global_init() {
  51. // CHECK:STDOUT: !entry:
  52. // CHECK:STDOUT: %.loc11_26: i32 = int_literal 4 [template = constants.%.3]
  53. // CHECK:STDOUT: %.loc11_27.1: %.2 = struct_literal (%.loc11_26)
  54. // CHECK:STDOUT: %.loc11_27.2: init %.2 = struct_init (%.loc11_26) to file.%x.var [template = constants.%struct]
  55. // CHECK:STDOUT: %.loc11_28: init %.2 = converted %.loc11_27.1, %.loc11_27.2 [template = constants.%struct]
  56. // CHECK:STDOUT: assign file.%x.var, %.loc11_28
  57. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  58. // CHECK:STDOUT: assign file.%y.var, <error>
  59. // CHECK:STDOUT: return
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: