fail_assign_to_empty.carbon 3.0 KB

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