fail_bad_condition.carbon 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/while/fail_bad_condition.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/while/fail_bad_condition.carbon
  10. fn While() {
  11. // CHECK:STDERR: fail_bad_condition.carbon:[[@LINE+6]]:9: error: cannot implicitly convert from `String` to `bool` [ImplicitAsConversionFailure]
  12. // CHECK:STDERR: while ("Hello") {}
  13. // CHECK:STDERR: ^~~~~~~~~
  14. // CHECK:STDERR: fail_bad_condition.carbon:[[@LINE+3]]:9: note: type `String` does not implement interface `ImplicitAs(bool)` [MissingImplInMemberAccessNote]
  15. // CHECK:STDERR: while ("Hello") {}
  16. // CHECK:STDERR: ^~~~~~~~~
  17. while ("Hello") {}
  18. }
  19. // CHECK:STDOUT: --- fail_bad_condition.carbon
  20. // CHECK:STDOUT:
  21. // CHECK:STDOUT: constants {
  22. // CHECK:STDOUT: %While.type: type = fn_type @While [template]
  23. // CHECK:STDOUT: %While: %While.type = struct_value () [template]
  24. // CHECK:STDOUT: %.2: String = string_literal "Hello" [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .ImplicitAs = %import_ref.1
  30. // CHECK:STDOUT: import Core//prelude
  31. // CHECK:STDOUT: import Core//prelude/...
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT:
  35. // CHECK:STDOUT: file {
  36. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  37. // CHECK:STDOUT: .Core = imports.%Core
  38. // CHECK:STDOUT: .While = %While.decl
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.import = import Core
  41. // CHECK:STDOUT: %While.decl: %While.type = fn_decl @While [template = constants.%While] {} {}
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: fn @While() {
  45. // CHECK:STDOUT: !entry:
  46. // CHECK:STDOUT: br !while.cond
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: !while.cond:
  49. // CHECK:STDOUT: %.loc18_10: String = string_literal "Hello" [template = constants.%.2]
  50. // CHECK:STDOUT: %.loc18_17: bool = converted %.loc18_10, <error> [template = <error>]
  51. // CHECK:STDOUT: if <error> br !while.body else br !while.done
  52. // CHECK:STDOUT:
  53. // CHECK:STDOUT: !while.body:
  54. // CHECK:STDOUT: br !while.cond
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: !while.done:
  57. // CHECK:STDOUT: return
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: