fail_field_name_mismatch.carbon 4.7 KB

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