fail_assign_to_empty.carbon 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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+3]]: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. var x: {} = {.a = 1};
  14. // CHECK:STDOUT: --- fail_assign_to_empty.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  18. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  19. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [template]
  20. // CHECK:STDOUT: }
  21. // CHECK:STDOUT:
  22. // CHECK:STDOUT: imports {
  23. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  24. // CHECK:STDOUT: import Core//prelude
  25. // CHECK:STDOUT: import Core//prelude/...
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: file {
  30. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  31. // CHECK:STDOUT: .Core = imports.%Core
  32. // CHECK:STDOUT: .x = %x
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: %Core.import = import Core
  35. // CHECK:STDOUT: %x.var: ref %empty_struct_type = var x
  36. // CHECK:STDOUT: %x: ref %empty_struct_type = bind_name x, %x.var
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT:
  39. // CHECK:STDOUT: fn @__global_init() {
  40. // CHECK:STDOUT: !entry:
  41. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  42. // CHECK:STDOUT: %.loc14: %struct_type.a = struct_literal (%int_1)
  43. // CHECK:STDOUT: assign file.%x.var, <error>
  44. // CHECK:STDOUT: return
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: