fail_field_name_mismatch.carbon 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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+4]]: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. // CHECK:STDERR:
  19. var y: {.b: i32} = x;
  20. // CHECK:STDOUT: --- fail_field_name_mismatch.carbon
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: constants {
  23. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  24. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  25. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [template]
  26. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  27. // CHECK:STDOUT: %struct_type.b.a15: type = struct_type {.b: Core.IntLiteral} [template]
  28. // CHECK:STDOUT: %struct_type.b.0a3: type = struct_type {.b: %i32} [template]
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: imports {
  32. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  33. // CHECK:STDOUT: .Int = %Core.Int
  34. // CHECK:STDOUT: import Core//prelude
  35. // CHECK:STDOUT: import Core//prelude/...
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: file {
  40. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  41. // CHECK:STDOUT: .Core = imports.%Core
  42. // CHECK:STDOUT: .x = %x
  43. // CHECK:STDOUT: .y = %y
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT: %Core.import = import Core
  46. // CHECK:STDOUT: name_binding_decl {
  47. // CHECK:STDOUT: %x.patt: %struct_type.a = binding_pattern x
  48. // CHECK:STDOUT: %.loc15_1: %struct_type.a = var_pattern %x.patt
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT: %x.var: ref %struct_type.a = var x
  51. // CHECK:STDOUT: %.loc15_16: type = splice_block %struct_type.a [template = constants.%struct_type.a] {
  52. // CHECK:STDOUT: %int_32.loc15: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  53. // CHECK:STDOUT: %i32.loc15: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  54. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [template = constants.%struct_type.a]
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: %x: ref %struct_type.a = bind_name x, %x.var
  57. // CHECK:STDOUT: name_binding_decl {
  58. // CHECK:STDOUT: %y.patt: %struct_type.b.0a3 = binding_pattern y
  59. // CHECK:STDOUT: %.loc21_1: %struct_type.b.0a3 = var_pattern %y.patt
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %y.var: ref %struct_type.b.0a3 = var y
  62. // CHECK:STDOUT: %.loc21_16: type = splice_block %struct_type.b [template = constants.%struct_type.b.0a3] {
  63. // CHECK:STDOUT: %int_32.loc21: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %i32.loc21: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  65. // CHECK:STDOUT: %struct_type.b: type = struct_type {.b: %i32} [template = constants.%struct_type.b.0a3]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %y: ref %struct_type.b.0a3 = bind_name y, %y.var
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: fn @__global_init() {
  71. // CHECK:STDOUT: !entry:
  72. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  73. // CHECK:STDOUT: %.loc15: %struct_type.b.a15 = struct_literal (%int_1)
  74. // CHECK:STDOUT: assign file.%x.var, <error>
  75. // CHECK:STDOUT: %x.ref: ref %struct_type.a = name_ref x, file.%x
  76. // CHECK:STDOUT: assign file.%y.var, <error>
  77. // CHECK:STDOUT: return
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT: