fail_convert_to_invalid.carbon 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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/class/fail_convert_to_invalid.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_convert_to_invalid.carbon
  10. class C {
  11. // CHECK:STDERR: fail_convert_to_invalid.carbon:[[@LINE+3]]:10: error: name `NoSuchType` not found
  12. // CHECK:STDERR: var a: NoSuchType;
  13. // CHECK:STDERR: ^~~~~~~~~~
  14. var a: NoSuchType;
  15. }
  16. fn Make() -> C {
  17. return {.a = 123};
  18. }
  19. // CHECK:STDOUT: --- fail_convert_to_invalid.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %C: type = class_type @C [template]
  23. // CHECK:STDOUT: %Make.type: type = fn_type @Make [template]
  24. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  25. // CHECK:STDOUT: %Make: %Make.type = struct_value () [template]
  26. // CHECK:STDOUT: %.2: i32 = int_literal 123 [template]
  27. // CHECK:STDOUT: %.3: type = struct_type {.a: i32} [template]
  28. // CHECK:STDOUT: }
  29. // CHECK:STDOUT:
  30. // CHECK:STDOUT: imports {
  31. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/operators
  34. // CHECK:STDOUT: import Core//prelude/types
  35. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  36. // CHECK:STDOUT: import Core//prelude/operators/as
  37. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  38. // CHECK:STDOUT: import Core//prelude/operators/comparison
  39. // CHECK:STDOUT: import Core//prelude/types/bool
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: file {
  44. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  45. // CHECK:STDOUT: .Core = imports.%Core
  46. // CHECK:STDOUT: .C = %C.decl
  47. // CHECK:STDOUT: .Make = %Make.decl
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.import = import Core
  50. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {}
  51. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {} {
  52. // CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [template = constants.%C]
  53. // CHECK:STDOUT: %return: ref %C = var <return slot>
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @C {
  58. // CHECK:STDOUT: %NoSuchType.ref: <error> = name_ref NoSuchType, <error> [template = <error>]
  59. // CHECK:STDOUT: %.loc15: <error> = field_decl a, element0 [template]
  60. // CHECK:STDOUT: %.loc16: <witness> = complete_type_witness <error> [template = <error>]
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: !members:
  63. // CHECK:STDOUT: .Self = constants.%C
  64. // CHECK:STDOUT: .a = %.loc15
  65. // CHECK:STDOUT: }
  66. // CHECK:STDOUT:
  67. // CHECK:STDOUT: fn @Make() -> %return: %C {
  68. // CHECK:STDOUT: !entry:
  69. // CHECK:STDOUT: %.loc19_16: i32 = int_literal 123 [template = constants.%.2]
  70. // CHECK:STDOUT: %.loc19_19: %.3 = struct_literal (%.loc19_16)
  71. // CHECK:STDOUT: return <error> to %return
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: