fail_too_few_values.carbon 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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: %int_32: Core.IntLiteral = int_value 32 [template]
  18. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  19. // CHECK:STDOUT: %struct_type.a.b: type = struct_type {.a: %i32, .b: %i32} [template]
  20. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  21. // CHECK:STDOUT: %struct_type.a: type = struct_type {.a: Core.IntLiteral} [template]
  22. // CHECK:STDOUT: }
  23. // CHECK:STDOUT:
  24. // CHECK:STDOUT: imports {
  25. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  26. // CHECK:STDOUT: .Int = %import_ref.187
  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: %x.var: ref %struct_type.a.b = var x
  39. // CHECK:STDOUT: %x: ref %struct_type.a.b = bind_name x, %x.var
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: fn @__global_init() {
  43. // CHECK:STDOUT: !entry:
  44. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  45. // CHECK:STDOUT: %.loc14: %struct_type.a = struct_literal (%int_1)
  46. // CHECK:STDOUT: assign file.%x.var, <error>
  47. // CHECK:STDOUT: return
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: