fail_assign_to_empty.carbon 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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: %empty_struct: %empty_struct_type = struct_value () [concrete]
  24. // CHECK:STDOUT: %pattern_type: type = pattern_type %empty_struct_type [concrete]
  25. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  26. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [concrete]
  27. // CHECK:STDOUT: %struct: %struct_type.a = struct_value (%int_1) [concrete]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  39. // CHECK:STDOUT: .Core = imports.%Core
  40. // CHECK:STDOUT: .x = %x
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: name_binding_decl {
  44. // CHECK:STDOUT: %x.patt: %pattern_type = ref_binding_pattern x [concrete]
  45. // CHECK:STDOUT: %x.var_patt: %pattern_type = var_pattern %x.patt [concrete]
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %x.var: ref %empty_struct_type = var %x.var_patt [concrete]
  48. // CHECK:STDOUT: %.loc19_9.1: type = splice_block %.loc19_9.3 [concrete = constants.%empty_struct_type] {
  49. // CHECK:STDOUT: %.loc19_9.2: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  50. // CHECK:STDOUT: %.loc19_9.3: type = converted %.loc19_9.2, constants.%empty_struct_type [concrete = constants.%empty_struct_type]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %x: ref %empty_struct_type = ref_binding x, %x.var [concrete = %x.var]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: fn @__global_init() {
  56. // CHECK:STDOUT: !entry:
  57. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  58. // CHECK:STDOUT: %.loc19: %struct_type.a = struct_literal (%int_1) [concrete = constants.%struct]
  59. // CHECK:STDOUT: assign file.%x.var, <error>
  60. // CHECK:STDOUT: return
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT: