fail_no_conversion.carbon 5.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 `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: %.1: Core.IntLiteral = int_value 32 [template]
  21. // CHECK:STDOUT: %Int.type: type = fn_type @Int [template]
  22. // CHECK:STDOUT: %Int: %Int.type = struct_value () [template]
  23. // CHECK:STDOUT: %i32: type = int_type signed, %.1 [template]
  24. // CHECK:STDOUT: %tuple.type.1: type = tuple_type (type, type) [template]
  25. // CHECK:STDOUT: %tuple.type.2: type = tuple_type (%i32, %i32) [template]
  26. // CHECK:STDOUT: %.3: Core.IntLiteral = int_value 1 [template]
  27. // CHECK:STDOUT: }
  28. // CHECK:STDOUT:
  29. // CHECK:STDOUT: imports {
  30. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  31. // CHECK:STDOUT: .Int = %import_ref.1
  32. // CHECK:STDOUT: .As = %import_ref.2
  33. // CHECK:STDOUT: import Core//prelude
  34. // CHECK:STDOUT: import Core//prelude/...
  35. // CHECK:STDOUT: }
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: file {
  39. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  40. // CHECK:STDOUT: .Core = imports.%Core
  41. // CHECK:STDOUT: .n = @__global_init.%n
  42. // CHECK:STDOUT: }
  43. // CHECK:STDOUT: %Core.import = import Core
  44. // CHECK:STDOUT: %.loc17_9: Core.IntLiteral = int_value 32 [template = constants.%.1]
  45. // CHECK:STDOUT: %int.make_type_signed.loc17_9: init type = call constants.%Int(%.loc17_9) [template = constants.%i32]
  46. // CHECK:STDOUT: %.loc17_14: Core.IntLiteral = int_value 32 [template = constants.%.1]
  47. // CHECK:STDOUT: %int.make_type_signed.loc17_14: init type = call constants.%Int(%.loc17_14) [template = constants.%i32]
  48. // CHECK:STDOUT: %.loc17_17.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc17_9, %int.make_type_signed.loc17_14)
  49. // CHECK:STDOUT: %.loc17_17.2: type = value_of_initializer %int.make_type_signed.loc17_9 [template = constants.%i32]
  50. // CHECK:STDOUT: %.loc17_17.3: type = converted %int.make_type_signed.loc17_9, %.loc17_17.2 [template = constants.%i32]
  51. // CHECK:STDOUT: %.loc17_17.4: type = value_of_initializer %int.make_type_signed.loc17_14 [template = constants.%i32]
  52. // CHECK:STDOUT: %.loc17_17.5: type = converted %int.make_type_signed.loc17_14, %.loc17_17.4 [template = constants.%i32]
  53. // CHECK:STDOUT: %.loc17_17.6: type = converted %.loc17_17.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  54. // CHECK:STDOUT: }
  55. // CHECK:STDOUT:
  56. // CHECK:STDOUT: fn @__global_init() {
  57. // CHECK:STDOUT: !entry:
  58. // CHECK:STDOUT: %.loc17_21: Core.IntLiteral = int_value 1 [template = constants.%.3]
  59. // CHECK:STDOUT: %.loc17_27: Core.IntLiteral = int_value 32 [template = constants.%.1]
  60. // CHECK:STDOUT: %int.make_type_signed.loc17_27: init type = call constants.%Int(%.loc17_27) [template = constants.%i32]
  61. // CHECK:STDOUT: %.loc17_32: Core.IntLiteral = int_value 32 [template = constants.%.1]
  62. // CHECK:STDOUT: %int.make_type_signed.loc17_32: init type = call constants.%Int(%.loc17_32) [template = constants.%i32]
  63. // CHECK:STDOUT: %.loc17_35.1: %tuple.type.1 = tuple_literal (%int.make_type_signed.loc17_27, %int.make_type_signed.loc17_32)
  64. // CHECK:STDOUT: %.loc17_35.2: type = value_of_initializer %int.make_type_signed.loc17_27 [template = constants.%i32]
  65. // CHECK:STDOUT: %.loc17_35.3: type = converted %int.make_type_signed.loc17_27, %.loc17_35.2 [template = constants.%i32]
  66. // CHECK:STDOUT: %.loc17_35.4: type = value_of_initializer %int.make_type_signed.loc17_32 [template = constants.%i32]
  67. // CHECK:STDOUT: %.loc17_35.5: type = converted %int.make_type_signed.loc17_32, %.loc17_35.4 [template = constants.%i32]
  68. // CHECK:STDOUT: %.loc17_35.6: type = converted %.loc17_35.1, constants.%tuple.type.2 [template = constants.%tuple.type.2]
  69. // CHECK:STDOUT: %.loc17_23.1: %tuple.type.2 = converted %.loc17_21, <error> [template = <error>]
  70. // CHECK:STDOUT: %.loc17_23.2: %i32 = tuple_access %.loc17_23.1, element0 [template = <error>]
  71. // CHECK:STDOUT: %n: %tuple.type.2 = bind_name n, <error>
  72. // CHECK:STDOUT: return
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT: