fail_field_name_mismatch.carbon 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 [StructInitMissingFieldInLiteral]
  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 [StructInitMissingFieldInConversion]
  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: %.1: Core.IntLiteral = int_value 32 [template]
  23. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  24. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  25. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  26. // CHECK:STDOUT: %.2: type = struct_type {.a: %i32} [template]
  27. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 1 [template]
  28. // CHECK:STDOUT: %.4: type = struct_type {.b: Core.IntLiteral} [template]
  29. // CHECK:STDOUT: %.5: type = struct_type {.b: %i32} [template]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  34. // CHECK:STDOUT: .Int = %import_ref
  35. // CHECK:STDOUT: import Core//prelude
  36. // CHECK:STDOUT: import Core//prelude/...
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT:
  40. // CHECK:STDOUT: file {
  41. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  42. // CHECK:STDOUT: .Core = imports.%Core
  43. // CHECK:STDOUT: .x = %x
  44. // CHECK:STDOUT: .y = %y
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: %.loc15_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  48. // CHECK:STDOUT: %int.make_type_signed.loc15: init type = call constants.%Int(%.loc15_13.1) [template = constants.%i32]
  49. // CHECK:STDOUT: %.loc15_13.2: type = value_of_initializer %int.make_type_signed.loc15 [template = constants.%i32]
  50. // CHECK:STDOUT: %.loc15_13.3: type = converted %int.make_type_signed.loc15, %.loc15_13.2 [template = constants.%i32]
  51. // CHECK:STDOUT: %.loc15_16: type = struct_type {.a: %i32} [template = constants.%.2]
  52. // CHECK:STDOUT: %x.var: ref %.2 = var x
  53. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  54. // CHECK:STDOUT: %.loc20_13.1: Core.IntLiteral = int_value 32 [template = constants.%.1]
  55. // CHECK:STDOUT: %int.make_type_signed.loc20: init type = call constants.%Int(%.loc20_13.1) [template = constants.%i32]
  56. // CHECK:STDOUT: %.loc20_13.2: type = value_of_initializer %int.make_type_signed.loc20 [template = constants.%i32]
  57. // CHECK:STDOUT: %.loc20_13.3: type = converted %int.make_type_signed.loc20, %.loc20_13.2 [template = constants.%i32]
  58. // CHECK:STDOUT: %.loc20_16: type = struct_type {.b: %i32} [template = constants.%.5]
  59. // CHECK:STDOUT: %y.var: ref %.5 = var y
  60. // CHECK:STDOUT: %y: ref %.5 = bind_name y, %y.var
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: fn @__global_init() {
  64. // CHECK:STDOUT: !entry:
  65. // CHECK:STDOUT: %.loc15_26: Core.IntLiteral = int_value 1 [template = constants.%.3]
  66. // CHECK:STDOUT: %.loc15_27: %.4 = struct_literal (%.loc15_26)
  67. // CHECK:STDOUT: assign file.%x.var, <error>
  68. // CHECK:STDOUT: %x.ref: ref %.2 = name_ref x, file.%x
  69. // CHECK:STDOUT: assign file.%y.var, <error>
  70. // CHECK:STDOUT: return
  71. // CHECK:STDOUT: }
  72. // CHECK:STDOUT: