fail_no_conversion.carbon 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 expression of type `Core.IntLiteral` to `(i32, i32)` with `as` [ConversionFailure]
  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 [concrete]
  22. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  23. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  24. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  25. // CHECK:STDOUT: %tuple.type.24b: type = tuple_type (type, type) [concrete]
  26. // CHECK:STDOUT: %tuple.type.d07: type = tuple_type (%i32, %i32) [concrete]
  27. // CHECK:STDOUT: %pattern_type.511: type = pattern_type %tuple.type.d07 [concrete]
  28. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete]
  29. // CHECK:STDOUT: %As.type.90f: type = generic_interface_type @As [concrete]
  30. // CHECK:STDOUT: %As.generic: %As.type.90f = struct_value () [concrete]
  31. // CHECK:STDOUT: }
  32. // CHECK:STDOUT:
  33. // CHECK:STDOUT: imports {
  34. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  35. // CHECK:STDOUT: .Int = %Core.Int
  36. // CHECK:STDOUT: .As = %Core.As
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  41. // CHECK:STDOUT: %Core.As: %As.type.90f = import_ref Core//prelude/operators/as, As, loaded [concrete = constants.%As.generic]
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: file {
  45. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  46. // CHECK:STDOUT: .Core = imports.%Core
  47. // CHECK:STDOUT: .n = %n
  48. // CHECK:STDOUT: }
  49. // CHECK:STDOUT: %Core.import = import Core
  50. // CHECK:STDOUT: name_binding_decl {
  51. // CHECK:STDOUT: %n.patt: %pattern_type.511 = binding_pattern n [concrete]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %.loc18_17.1: type = splice_block %.loc18_17.3 [concrete = constants.%tuple.type.d07] {
  54. // CHECK:STDOUT: %int_32.loc18_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  55. // CHECK:STDOUT: %i32.loc18_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  56. // CHECK:STDOUT: %int_32.loc18_14: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  57. // CHECK:STDOUT: %i32.loc18_14: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  58. // CHECK:STDOUT: %.loc18_17.2: %tuple.type.24b = tuple_literal (%i32.loc18_9, %i32.loc18_14)
  59. // CHECK:STDOUT: %.loc18_17.3: type = converted %.loc18_17.2, constants.%tuple.type.d07 [concrete = constants.%tuple.type.d07]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %tuple.elem0: %i32 = tuple_access @__global_init.%.loc18_23, element0 [concrete = <error>]
  62. // CHECK:STDOUT: %n: %tuple.type.d07 = bind_name n, <error>
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT:
  65. // CHECK:STDOUT: fn @__global_init() {
  66. // CHECK:STDOUT: !entry:
  67. // CHECK:STDOUT: %int_1: Core.IntLiteral = int_value 1 [concrete = constants.%int_1]
  68. // CHECK:STDOUT: %int_32.loc18_27: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  69. // CHECK:STDOUT: %i32.loc18_27: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  70. // CHECK:STDOUT: %int_32.loc18_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  71. // CHECK:STDOUT: %i32.loc18_32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  72. // CHECK:STDOUT: %.loc18_35.1: %tuple.type.24b = tuple_literal (%i32.loc18_27, %i32.loc18_32)
  73. // CHECK:STDOUT: %.loc18_35.2: type = converted %.loc18_35.1, constants.%tuple.type.d07 [concrete = constants.%tuple.type.d07]
  74. // CHECK:STDOUT: %.loc18_23: %tuple.type.d07 = converted %int_1, <error> [concrete = <error>]
  75. // CHECK:STDOUT: return
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: