fail_too_few_values.carbon 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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_too_few_values.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_too_few_values.carbon
  10. // CHECK:STDERR: fail_too_few_values.carbon:[[@LINE+3]]:29: error: cannot initialize struct with 2 fields from struct with 1 field [StructInitElementCountMismatch]
  11. // CHECK:STDERR: var x: {.a: i32, .b: i32} = {.a = 1};
  12. // CHECK:STDERR: ^~~~~~~~
  13. var x: {.a: i32, .b: i32} = {.a = 1};
  14. // CHECK:STDOUT: --- fail_too_few_values.carbon
  15. // CHECK:STDOUT:
  16. // CHECK:STDOUT: constants {
  17. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  18. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  19. // CHECK:STDOUT: %.1: type = struct_type {.a: i32, .b: i32} [template]
  20. // CHECK:STDOUT: %.3: i32 = int_value 1 [template]
  21. // CHECK:STDOUT: %.4: type = struct_type {.a: i32} [template]
  22. // CHECK:STDOUT: }
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: imports {
  25. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  26. // CHECK:STDOUT: .Int32 = %import_ref
  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 [template] {
  34. // CHECK:STDOUT: .Core = imports.%Core
  35. // CHECK:STDOUT: .x = %x
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT: %Core.import = import Core
  38. // CHECK:STDOUT: %int.make_type_32.loc14_13: init type = call constants.%Int32() [template = i32]
  39. // CHECK:STDOUT: %.loc14_13.1: type = value_of_initializer %int.make_type_32.loc14_13 [template = i32]
  40. // CHECK:STDOUT: %.loc14_13.2: type = converted %int.make_type_32.loc14_13, %.loc14_13.1 [template = i32]
  41. // CHECK:STDOUT: %int.make_type_32.loc14_22: init type = call constants.%Int32() [template = i32]
  42. // CHECK:STDOUT: %.loc14_22.1: type = value_of_initializer %int.make_type_32.loc14_22 [template = i32]
  43. // CHECK:STDOUT: %.loc14_22.2: type = converted %int.make_type_32.loc14_22, %.loc14_22.1 [template = i32]
  44. // CHECK:STDOUT: %.loc14_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.1]
  45. // CHECK:STDOUT: %x.var: ref %.1 = var x
  46. // CHECK:STDOUT: %x: ref %.1 = bind_name x, %x.var
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT:
  49. // CHECK:STDOUT: fn @__global_init() {
  50. // CHECK:STDOUT: !entry:
  51. // CHECK:STDOUT: %.loc14_35: i32 = int_value 1 [template = constants.%.3]
  52. // CHECK:STDOUT: %.loc14_36: %.4 = struct_literal (%.loc14_35)
  53. // CHECK:STDOUT: assign file.%x.var, <error>
  54. // CHECK:STDOUT: return
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT: