fail_field_name_mismatch.carbon 3.0 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_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: %int_32: Core.IntLiteral = int_value 32 [template]
  23. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  24. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [template]
  25. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  26. // CHECK:STDOUT: %struct_type.b.1: type = struct_type {.b: Core.IntLiteral} [template]
  27. // CHECK:STDOUT: %struct_type.b.2: 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: .Int = %import_ref.1
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .x = %x
  42. // CHECK:STDOUT: .y = %y
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core.import = import Core
  45. // CHECK:STDOUT: %x.var: ref %struct_type.a = var x
  46. // CHECK:STDOUT: %x: ref %struct_type.a = bind_name x, %x.var
  47. // CHECK:STDOUT: %y.var: ref %struct_type.b.2 = var y
  48. // CHECK:STDOUT: %y: ref %struct_type.b.2 = bind_name y, %y.var
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @__global_init() {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  54. // CHECK:STDOUT: %.loc15: %struct_type.b.1 = struct_literal (%int_1)
  55. // CHECK:STDOUT: assign file.%x.var, <error>
  56. // CHECK:STDOUT: %x.ref: ref %struct_type.a = name_ref x, file.%x
  57. // CHECK:STDOUT: assign file.%y.var, <error>
  58. // CHECK:STDOUT: return
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT: