fail_assign_empty.carbon 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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_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_empty.carbon
  10. // CHECK:STDERR: fail_assign_empty.carbon:[[@LINE+3]]:20: error: cannot initialize struct with 1 field from struct with 0 fields [StructInitElementCountMismatch]
  11. // CHECK:STDERR: var x: {.a: i32} = {};
  12. // CHECK:STDERR: ^~
  13. var x: {.a: i32} = {};
  14. // CHECK:STDOUT: --- fail_assign_empty.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  19. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [template]
  20. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  21. // CHECK:STDOUT: }
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: imports {
  24. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  25. // CHECK:STDOUT: .Int = %import_ref.187
  26. // CHECK:STDOUT: import Core//prelude
  27. // CHECK:STDOUT: import Core//prelude/...
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT:
  31. // CHECK:STDOUT: file {
  32. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  33. // CHECK:STDOUT: .Core = imports.%Core
  34. // CHECK:STDOUT: .x = %x
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core.import = import Core
  37. // CHECK:STDOUT: %x.var: ref %struct_type.a = var x
  38. // CHECK:STDOUT: %x: ref %struct_type.a = bind_name x, %x.var
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: fn @__global_init() {
  42. // CHECK:STDOUT: !entry:
  43. // CHECK:STDOUT: %.loc14: %empty_struct_type = struct_literal ()
  44. // CHECK:STDOUT: assign file.%x.var, <error>
  45. // CHECK:STDOUT: return
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: