fail_no_conversion.carbon 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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+7]]: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+4]]: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. // CHECK:STDERR:
  17. let n: (i32, i32) = 1 as (i32, i32);
  18. // CHECK:STDOUT: --- fail_no_conversion.carbon
  19. // CHECK:STDOUT:
  20. // CHECK:STDOUT: constants {
  21. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  22. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  23. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [template]
  24. // CHECK:STDOUT: %tuple.type.d07: type = tuple_type (%i32, %i32) [template]
  25. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template]
  26. // CHECK:STDOUT: }
  27. // CHECK:STDOUT:
  28. // CHECK:STDOUT: imports {
  29. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  30. // CHECK:STDOUT: .Int = %Core.Int
  31. // CHECK:STDOUT: .As = %Core.As
  32. // CHECK:STDOUT: import Core//prelude
  33. // CHECK:STDOUT: import Core//prelude/...
  34. // CHECK:STDOUT: }
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT:
  37. // CHECK:STDOUT: file {
  38. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  39. // CHECK:STDOUT: .Core = imports.%Core
  40. // CHECK:STDOUT: .n = %n
  41. // CHECK:STDOUT: }
  42. // CHECK:STDOUT: %Core.import = import Core
  43. // CHECK:STDOUT: name_binding_decl {
  44. // CHECK:STDOUT: %n.patt: %tuple.type.d07 = binding_pattern n
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT: %.loc18_17.1: type = splice_block %.loc18_17.3 [template = constants.%tuple.type.d07] {
  47. // CHECK:STDOUT: %int_32.loc18_9: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  48. // CHECK:STDOUT: %i32.loc18_9: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  49. // CHECK:STDOUT: %int_32.loc18_14: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  50. // CHECK:STDOUT: %i32.loc18_14: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  51. // CHECK:STDOUT: %.loc18_17.2: %tuple.type.24b = tuple_literal (%i32.loc18_9, %i32.loc18_14)
  52. // CHECK:STDOUT: %.loc18_17.3: type = converted %.loc18_17.2, constants.%tuple.type.d07 [template = constants.%tuple.type.d07]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT: %tuple.elem0: %i32 = tuple_access @__global_init.%.loc18_23, element0 [template = <error>]
  55. // CHECK:STDOUT: %n: %tuple.type.d07 = bind_name n, <error>
  56. // CHECK:STDOUT: }
  57. // CHECK:STDOUT:
  58. // CHECK:STDOUT: fn @__global_init() {
  59. // CHECK:STDOUT: !entry:
  60. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [template = constants.%int_1]
  61. // CHECK:STDOUT: %int_32.loc18_27: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  62. // CHECK:STDOUT: %i32.loc18_27: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  63. // CHECK:STDOUT: %int_32.loc18_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  64. // CHECK:STDOUT: %i32.loc18_32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc18_35.1: %tuple.type.24b = tuple_literal (%i32.loc18_27, %i32.loc18_32)
  66. // CHECK:STDOUT: %.loc18_35.2: type = converted %.loc18_35.1, constants.%tuple.type.d07 [template = constants.%tuple.type.d07]
  67. // CHECK:STDOUT: %.loc18_23: %tuple.type.d07 = converted %int_1, <error> [template = <error>]
  68. // CHECK:STDOUT: return
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT: