fail_field_name_mismatch.carbon 4.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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_field_name_mismatch.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_field_name_mismatch.carbon
  10. // CHECK:STDERR: fail_field_name_mismatch.carbon:[[@LINE+4]]:20: error: missing value for field `a` in struct initialization
  11. // CHECK:STDERR: var x: {.a: i32} = {.b = 1};
  12. // CHECK:STDERR: ^~~~~~~~
  13. // CHECK:STDERR:
  14. var x: {.a: i32} = {.b = 1};
  15. // CHECK:STDERR: fail_field_name_mismatch.carbon:[[@LINE+3]]:20: error: cannot convert from struct type `{.a: i32}` to `{.b: i32}`: missing field `b` in source type
  16. // CHECK:STDERR: var y: {.b: i32} = x;
  17. // CHECK:STDERR: ^
  18. var y: {.b: i32} = x;
  19. // CHECK:STDOUT: --- fail_field_name_mismatch.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  23. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  24. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  25. // CHECK:STDOUT: %.2: type = struct_type {.a: i32} [template]
  26. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  27. // CHECK:STDOUT: %.4: type = struct_type {.b: i32} [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: .Int32 = %import_ref
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/operators
  35. // CHECK:STDOUT: import Core//prelude/types
  36. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  37. // CHECK:STDOUT: import Core//prelude/operators/as
  38. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  39. // CHECK:STDOUT: import Core//prelude/operators/comparison
  40. // CHECK:STDOUT: import Core//prelude/types/bool
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: file {
  46. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  47. // CHECK:STDOUT: .Core = imports.%Core
  48. // CHECK:STDOUT: .x = %x
  49. // CHECK:STDOUT: .y = %y
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %Core.import = import Core
  52. // CHECK:STDOUT: %int.make_type_32.loc15: init type = call constants.%Int32() [template = i32]
  53. // CHECK:STDOUT: %.loc15_13.1: type = value_of_initializer %int.make_type_32.loc15 [template = i32]
  54. // CHECK:STDOUT: %.loc15_13.2: type = converted %int.make_type_32.loc15, %.loc15_13.1 [template = i32]
  55. // CHECK:STDOUT: %.loc15_16: type = struct_type {.a: i32} [template = constants.%.2]
  56. // CHECK:STDOUT: %x.var: ref %.2 = var x
  57. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  58. // CHECK:STDOUT: %int.make_type_32.loc20: init type = call constants.%Int32() [template = i32]
  59. // CHECK:STDOUT: %.loc20_13.1: type = value_of_initializer %int.make_type_32.loc20 [template = i32]
  60. // CHECK:STDOUT: %.loc20_13.2: type = converted %int.make_type_32.loc20, %.loc20_13.1 [template = i32]
  61. // CHECK:STDOUT: %.loc20_16: type = struct_type {.b: i32} [template = constants.%.4]
  62. // CHECK:STDOUT: %y.var: ref %.4 = var y
  63. // CHECK:STDOUT: %y: ref %.4 = bind_name y, %y.var
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: fn @__global_init() {
  69. // CHECK:STDOUT: !entry:
  70. // CHECK:STDOUT: %.loc15_26: i32 = int_literal 1 [template = constants.%.3]
  71. // CHECK:STDOUT: %.loc15_27: %.4 = struct_literal (%.loc15_26)
  72. // CHECK:STDOUT: assign file.%x.var, <error>
  73. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  74. // CHECK:STDOUT: assign file.%y.var, <error>
  75. // CHECK:STDOUT: return
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: