fail_invalid.carbon 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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/choice/fail_invalid.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/choice/fail_invalid.carbon
  10. // --- fail_no_alternative_construct.carbon
  11. library "[[@TEST_NAME]]";
  12. choice Never {}
  13. fn F() {
  14. // TODO: Can we produce a better diagnostic?
  15. // CHECK:STDERR: fail_no_alternative_construct.carbon:[[@LINE+4]]:22: error: cannot initialize class with 1 field from struct with 0 fields [StructInitElementCountMismatch]
  16. // CHECK:STDERR: let never: Never = {};
  17. // CHECK:STDERR: ^~
  18. // CHECK:STDERR:
  19. let never: Never = {};
  20. }
  21. // CHECK:STDOUT: --- fail_no_alternative_construct.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Never: type = class_type @Never [concrete]
  25. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  26. // CHECK:STDOUT: %struct_type.discriminant: type = struct_type {.discriminant: %empty_tuple.type} [concrete]
  27. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.discriminant [concrete]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  30. // CHECK:STDOUT: %pattern_type: type = pattern_type %Never [concrete]
  31. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  36. // CHECK:STDOUT: import Core//prelude
  37. // CHECK:STDOUT: import Core//prelude/...
  38. // CHECK:STDOUT: }
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT:
  41. // CHECK:STDOUT: file {
  42. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  43. // CHECK:STDOUT: .Core = imports.%Core
  44. // CHECK:STDOUT: .Never = %Never.decl
  45. // CHECK:STDOUT: .F = %F.decl
  46. // CHECK:STDOUT: }
  47. // CHECK:STDOUT: %Core.import = import Core
  48. // CHECK:STDOUT: %Never.decl: type = class_decl @Never [concrete = constants.%Never] {} {}
  49. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {} {}
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: class @Never {
  53. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.discriminant [concrete = constants.%complete_type]
  54. // CHECK:STDOUT: complete_type_witness = %complete_type
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !members:
  57. // CHECK:STDOUT: .Self = constants.%Never
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT:
  60. // CHECK:STDOUT: fn @F() {
  61. // CHECK:STDOUT: !entry:
  62. // CHECK:STDOUT: name_binding_decl {
  63. // CHECK:STDOUT: %never.patt: %pattern_type = binding_pattern never [concrete]
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %.loc11_23.1: %empty_struct_type = struct_literal ()
  66. // CHECK:STDOUT: %Never.ref: type = name_ref Never, file.%Never.decl [concrete = constants.%Never]
  67. // CHECK:STDOUT: %.loc11_23.2: ref %Never = temporary_storage
  68. // CHECK:STDOUT: %.loc11_23.3: ref %Never = temporary %.loc11_23.2, <error> [concrete = <error>]
  69. // CHECK:STDOUT: %.loc11_23.4: ref %Never = converted %.loc11_23.1, %.loc11_23.3 [concrete = <error>]
  70. // CHECK:STDOUT: %never: ref %Never = bind_name never, %.loc11_23.4
  71. // CHECK:STDOUT: return
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: