fail_too_few_values.carbon 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 field(s) from struct with 1 field(s).
  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: %.1: type = tuple_type () [template]
  19. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  20. // CHECK:STDOUT: %.2: type = struct_type {.a: i32, .b: i32} [template]
  21. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  22. // CHECK:STDOUT: %.4: i32 = int_literal 1 [template]
  23. // CHECK:STDOUT: %.5: type = struct_type {.a: i32} [template]
  24. // CHECK:STDOUT: }
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: file {
  27. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  28. // CHECK:STDOUT: .Core = %Core
  29. // CHECK:STDOUT: .x = %x
  30. // CHECK:STDOUT: }
  31. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  32. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  33. // CHECK:STDOUT: %int.make_type_32.loc14_13: init type = call constants.%Int32() [template = i32]
  34. // CHECK:STDOUT: %.loc14_13.1: type = value_of_initializer %int.make_type_32.loc14_13 [template = i32]
  35. // CHECK:STDOUT: %.loc14_13.2: type = converted %int.make_type_32.loc14_13, %.loc14_13.1 [template = i32]
  36. // CHECK:STDOUT: %import_ref.2: %Int32.type = import_ref ir3, inst+3, loaded [template = constants.%Int32]
  37. // CHECK:STDOUT: %int.make_type_32.loc14_22: init type = call constants.%Int32() [template = i32]
  38. // CHECK:STDOUT: %.loc14_22.1: type = value_of_initializer %int.make_type_32.loc14_22 [template = i32]
  39. // CHECK:STDOUT: %.loc14_22.2: type = converted %int.make_type_32.loc14_22, %.loc14_22.1 [template = i32]
  40. // CHECK:STDOUT: %.loc14_25: type = struct_type {.a: i32, .b: i32} [template = constants.%.2]
  41. // CHECK:STDOUT: %x.var: ref %.2 = var x
  42. // CHECK:STDOUT: %x: ref %.2 = bind_name x, %x.var
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT:
  45. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: fn @__global_init() {
  48. // CHECK:STDOUT: !entry:
  49. // CHECK:STDOUT: %.loc14_35: i32 = int_literal 1 [template = constants.%.4]
  50. // CHECK:STDOUT: %.loc14_36: %.5 = struct_literal (%.loc14_35)
  51. // CHECK:STDOUT: assign file.%x.var, <error>
  52. // CHECK:STDOUT: return
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: