fail_too_few_values.carbon 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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_too_few_values.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/struct/fail_too_few_values.carbon
  14. // CHECK:STDERR: fail_too_few_values.carbon:[[@LINE+4]]:29: error: cannot initialize struct with 2 fields from struct with 1 field [StructInitElementCountMismatch]
  15. // CHECK:STDERR: var x: {.a: i32, .b: i32} = {.a = 1};
  16. // CHECK:STDERR: ^~~~~~~~
  17. // CHECK:STDERR:
  18. var x: {.a: i32, .b: i32} = {.a = 1};
  19. // CHECK:STDOUT: --- fail_too_few_values.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.b: type = struct_type {.a: %i32, .b: %i32} [concrete]
  27. // CHECK:STDOUT: %pattern_type.851: type = pattern_type %struct_type.a.b [concrete]
  28. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  29. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [concrete]
  30. // CHECK:STDOUT: %struct: %struct_type.a = struct_value (%int_1) [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  35. // CHECK:STDOUT: .Int = %Core.Int
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .x = %x
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: name_binding_decl {
  49. // CHECK:STDOUT: %x.patt: %pattern_type.851 = ref_binding_pattern x [concrete]
  50. // CHECK:STDOUT: %x.var_patt: %pattern_type.851 = var_pattern %x.patt [concrete]
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %x.var: ref %struct_type.a.b = var %x.var_patt [concrete]
  53. // CHECK:STDOUT: %.loc19: type = splice_block %struct_type.a.b [concrete = constants.%struct_type.a.b] {
  54. // CHECK:STDOUT: %i32.loc19_13: type = type_literal constants.%i32 [concrete = constants.%i32]
  55. // CHECK:STDOUT: %i32.loc19_22: type = type_literal constants.%i32 [concrete = constants.%i32]
  56. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [concrete = constants.%struct_type.a.b]
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: %x: ref %struct_type.a.b = ref_binding x, %x.var [concrete = %x.var]
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: fn @__global_init() {
  62. // CHECK:STDOUT: !entry:
  63. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  64. // CHECK:STDOUT: %.loc19: %struct_type.a = struct_literal (%int_1) [concrete = constants.%struct]
  65. // CHECK:STDOUT: assign file.%x.var, <error>
  66. // CHECK:STDOUT: return
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: