fail_convert_to_invalid.carbon 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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: file {
  31. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  32. // CHECK:STDOUT: .Core = %Core
  33. // CHECK:STDOUT: .C = %C.decl
  34. // CHECK:STDOUT: .Make = %Make.decl
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: %Core: <namespace> = namespace [template] {}
  37. // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {}
  38. // CHECK:STDOUT: %Make.decl: %Make.type = fn_decl @Make [template = constants.%Make] {
  39. // CHECK:STDOUT: %C.ref: type = name_ref C, %C.decl [template = constants.%C]
  40. // CHECK:STDOUT: @Make.%return: ref %C = var <return slot>
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: class @C {
  45. // CHECK:STDOUT: %NoSuchType.ref: <error> = name_ref NoSuchType, <error> [template = <error>]
  46. // CHECK:STDOUT: %.loc15: <error> = field_decl a, element0 [template]
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: !members:
  49. // CHECK:STDOUT: .Self = constants.%C
  50. // CHECK:STDOUT: .a = %.loc15
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: fn @Make() -> %return: %C {
  54. // CHECK:STDOUT: !entry:
  55. // CHECK:STDOUT: %.loc19_16: i32 = int_literal 123 [template = constants.%.2]
  56. // CHECK:STDOUT: %.loc19_19: %.3 = struct_literal (%.loc19_16)
  57. // CHECK:STDOUT: return <error> to %return
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: