fail_assign_empty.carbon 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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+4]]: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. // CHECK:STDERR:
  14. var x: {.a: i32} = {};
  15. // CHECK:STDOUT: --- fail_assign_empty.carbon
  16. // CHECK:STDOUT:
  17. // CHECK:STDOUT: constants {
  18. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  19. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  20. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete]
  21. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  22. // CHECK:STDOUT: }
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: imports {
  25. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  26. // CHECK:STDOUT: .Int = %Core.Int
  27. // CHECK:STDOUT: import Core//prelude
  28. // CHECK:STDOUT: import Core//prelude/...
  29. // CHECK:STDOUT: }
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: file {
  33. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  34. // CHECK:STDOUT: .Core = imports.%Core
  35. // CHECK:STDOUT: .x = %x
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core.import = import Core
  38. // CHECK:STDOUT: name_binding_decl {
  39. // CHECK:STDOUT: %x.patt: %struct_type.a = binding_pattern x
  40. // CHECK:STDOUT: %.loc15_1: %struct_type.a = var_pattern %x.patt
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %x.var: ref %struct_type.a = var x
  43. // CHECK:STDOUT: %.loc15_16: type = splice_block %struct_type.a [concrete = constants.%struct_type.a] {
  44. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  45. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  46. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete = constants.%struct_type.a]
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %x: ref %struct_type.a = bind_name x, %x.var
  49. // CHECK:STDOUT: }
  50. // CHECK:STDOUT:
  51. // CHECK:STDOUT: fn @__global_init() {
  52. // CHECK:STDOUT: !entry:
  53. // CHECK:STDOUT: %.loc15: %empty_struct_type = struct_literal ()
  54. // CHECK:STDOUT: assign file.%x.var, <error>
  55. // CHECK:STDOUT: return
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: