fail_no_conversion.carbon 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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/as/fail_no_conversion.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/as/fail_no_conversion.carbon
  10. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE+6]]:21: error: cannot convert from `Core.IntLiteral` to `(i32, i32)` with `as` [ExplicitAsConversionFailure]
  11. // CHECK:STDERR: let n: (i32, i32) = 1 as (i32, i32);
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  13. // CHECK:STDERR: fail_no_conversion.carbon:[[@LINE+3]]:21: note: type `Core.IntLiteral` does not implement interface `Core.As((i32, i32))` [MissingImplInMemberAccessNote]
  14. // CHECK:STDERR: let n: (i32, i32) = 1 as (i32, i32);
  15. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  16. let n: (i32, i32) = 1 as (i32, i32);
  17. // CHECK:STDOUT: --- fail_no_conversion.carbon
  18. // CHECK:STDOUT:
  19. // CHECK:STDOUT: constants {
  20. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  21. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  22. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [template]
  23. // CHECK:STDOUT: %tuple.type.471: type = tuple_type (%i32, %i32) [template]
  24. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  25. // CHECK:STDOUT: }
  26. // CHECK:STDOUT:
  27. // CHECK:STDOUT: imports {
  28. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  29. // CHECK:STDOUT: .Int = %import_ref.187
  30. // CHECK:STDOUT: .As = %import_ref.166
  31. // CHECK:STDOUT: import Core//prelude
  32. // CHECK:STDOUT: import Core//prelude/...
  33. // CHECK:STDOUT: }
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: file {
  37. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  38. // CHECK:STDOUT: .Core = imports.%Core
  39. // CHECK:STDOUT: .n = @__global_init.%n
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT: %Core.import = import Core
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: fn @__global_init() {
  45. // CHECK:STDOUT: !entry:
  46. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  47. // CHECK:STDOUT: %int_32.loc17_27: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  48. // CHECK:STDOUT: %i32.loc17_27: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  49. // CHECK:STDOUT: %int_32.loc17_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  50. // CHECK:STDOUT: %i32.loc17_32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  51. // CHECK:STDOUT: %.loc17_35.1: %tuple.type.24b = tuple_literal (%i32.loc17_27, %i32.loc17_32)
  52. // CHECK:STDOUT: %.loc17_35.2: type = converted %.loc17_35.1, constants.%tuple.type.471 [template = constants.%tuple.type.471]
  53. // CHECK:STDOUT: %.loc17_23: %tuple.type.471 = converted %int_1, <error> [template = <error>]
  54. // CHECK:STDOUT: %tuple.elem0: %i32 = tuple_access %.loc17_23, element0 [template = <error>]
  55. // CHECK:STDOUT: %n: %tuple.type.471 = bind_name n, <error>
  56. // CHECK:STDOUT: return
  57. // CHECK:STDOUT: }
  58. // CHECK:STDOUT: