fail_too_few_values.carbon 3.2 KB

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