fail_assign_to_empty.carbon 2.6 KB

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