fail_assign_empty.carbon 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/struct/fail_assign_empty.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_assign_empty.carbon
  14. // CHECK:STDERR: fail_assign_empty.carbon:[[@LINE+4]]:20: error: cannot initialize struct with 1 field from struct with 0 fields [StructInitElementCountMismatch]
  15. // CHECK:STDERR: var x: {.a: i32} = {};
  16. // CHECK:STDERR: ^~
  17. // CHECK:STDERR:
  18. var x: {.a: i32} = {};
  19. // CHECK:STDOUT: --- fail_assign_empty.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  23. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  24. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  25. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  26. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete]
  27. // CHECK:STDOUT: %pattern_type.268: type = pattern_type %struct_type.a [concrete]
  28. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  29. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT:
  32. // CHECK:STDOUT: imports {
  33. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  34. // CHECK:STDOUT: .Int = %Core.Int
  35. // CHECK:STDOUT: import Core//prelude
  36. // CHECK:STDOUT: import Core//prelude/...
  37. // CHECK:STDOUT: }
  38. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .x = %x
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %Core.import = import Core
  47. // CHECK:STDOUT: name_binding_decl {
  48. // CHECK:STDOUT: %x.patt: %pattern_type.268 = ref_binding_pattern x [concrete]
  49. // CHECK:STDOUT: %x.var_patt: %pattern_type.268 = var_pattern %x.patt [concrete]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT: %x.var: ref %struct_type.a = var %x.var_patt [concrete]
  52. // CHECK:STDOUT: %.loc19: type = splice_block %struct_type.a [concrete = constants.%struct_type.a] {
  53. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  54. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  55. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: %i32} [concrete = constants.%struct_type.a]
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT: %x: ref %struct_type.a = ref_binding x, %x.var [concrete = %x.var]
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @__global_init() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: %.loc19: %empty_struct_type = struct_literal () [concrete = constants.%empty_struct]
  63. // CHECK:STDOUT: assign file.%x.var, <error>
  64. // CHECK:STDOUT: return
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT: