fail_assign_to_empty.carbon 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 field(s) from struct with 1 field(s).
  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: %.1: type = struct_type {} [template]
  18. // CHECK:STDOUT: %.2: type = tuple_type () [template]
  19. // CHECK:STDOUT: %.3: i32 = int_literal 1 [template]
  20. // CHECK:STDOUT: %.4: type = struct_type {.a: i32} [template]
  21. // CHECK:STDOUT: }
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: file {
  24. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  25. // CHECK:STDOUT: .Core = %Core
  26. // CHECK:STDOUT: .x = %x
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  29. // CHECK:STDOUT: %.loc14_9.1: %.1 = struct_literal ()
  30. // CHECK:STDOUT: %.loc14_9.2: type = converted %.loc14_9.1, constants.%.1 [template = constants.%.1]
  31. // CHECK:STDOUT: %x.var: ref %.1 = var x
  32. // CHECK:STDOUT: %x: ref %.1 = bind_name x, %x.var
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: fn @__global_init() {
  36. // CHECK:STDOUT: !entry:
  37. // CHECK:STDOUT: %.loc14_19: i32 = int_literal 1 [template = constants.%.3]
  38. // CHECK:STDOUT: %.loc14_20: %.4 = struct_literal (%.loc14_19)
  39. // CHECK:STDOUT: assign file.%x.var, <error>
  40. // CHECK:STDOUT: return
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: