fail_assign_to_empty.carbon 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  6. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  7. //
  8. // AUTOUPDATE
  9. // TIP: To test this file alone, run:
  10. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/struct/fail_assign_to_empty.carbon
  11. // TIP: To dump output, run:
  12. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_assign_to_empty.carbon
  13. // CHECK:STDERR: fail_assign_to_empty.carbon:[[@LINE+4]]:13: error: cannot initialize struct with 0 fields from struct with 1 field [StructInitElementCountMismatch]
  14. // CHECK:STDERR: var x: {} = {.a = 1};
  15. // CHECK:STDERR: ^~~~~~~~
  16. // CHECK:STDERR:
  17. var x: {} = {.a = 1};
  18. // CHECK:STDOUT: --- fail_assign_to_empty.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  22. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_struct_type [concrete]
  23. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  24. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [concrete]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  29. // CHECK:STDOUT: import Core//prelude
  30. // CHECK:STDOUT: import Core//prelude/...
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: file {
  35. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  36. // CHECK:STDOUT: .Core = imports.%Core
  37. // CHECK:STDOUT: .x = %x
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core.import = import Core
  40. // CHECK:STDOUT: name_binding_decl {
  41. // CHECK:STDOUT: %x.patt: %pattern_type = binding_pattern x [concrete]
  42. // CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete]
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %x.var: ref %empty_struct_type = var %x.var_patt [concrete]
  45. // CHECK:STDOUT: %.loc18_9.1: type = splice_block %.loc18_9.3 [concrete = constants.%empty_struct_type] {
  46. // CHECK:STDOUT: %.loc18_9.2: %empty_struct_type = struct_literal ()
  47. // CHECK:STDOUT: %.loc18_9.3: type = converted %.loc18_9.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %x: ref %empty_struct_type = bind_name x, %x.var [concrete = %x.var]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: fn @__global_init() {
  53. // CHECK:STDOUT: !entry:
  54. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  55. // CHECK:STDOUT: %.loc18: %struct_type.a = struct_literal (%int_1)
  56. // CHECK:STDOUT: assign file.%x.var, <error>
  57. // CHECK:STDOUT: return
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: