fail_generic.carbon 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/let/fail_generic.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/let/fail_generic.carbon
  14. // TODO: Should this be valid?
  15. fn F(a: i32) -> i32 {
  16. let T:! type = i32;
  17. // CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:14: error: cannot implicitly convert expression of type `Core.IntLiteral` to `T` [ConversionFailure]
  18. // CHECK:STDERR: let x: T = 5;
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:14: note: type `Core.IntLiteral` does not implement interface `Core.ImplicitAs(T)` [MissingImplInMemberAccessNote]
  21. // CHECK:STDERR: let x: T = 5;
  22. // CHECK:STDERR: ^
  23. // CHECK:STDERR:
  24. let x: T = 5;
  25. // CHECK:STDERR: fail_generic.carbon:[[@LINE+7]]:3: error: cannot implicitly convert expression of type `T` to `i32` [ConversionFailure]
  26. // CHECK:STDERR: return x;
  27. // CHECK:STDERR: ^~~~~~~~~
  28. // CHECK:STDERR: fail_generic.carbon:[[@LINE+4]]:3: note: type `T` does not implement interface `Core.ImplicitAs(i32)` [MissingImplInMemberAccessNote]
  29. // CHECK:STDERR: return x;
  30. // CHECK:STDERR: ^~~~~~~~~
  31. // CHECK:STDERR:
  32. return x;
  33. }
  34. // CHECK:STDOUT: --- fail_generic.carbon
  35. // CHECK:STDOUT:
  36. // CHECK:STDOUT: constants {
  37. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  38. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  39. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  40. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  41. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  42. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  43. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  44. // CHECK:STDOUT: %type: type = facet_type <type> [concrete]
  45. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self]
  46. // CHECK:STDOUT: %T: type = symbolic_binding T, 0 [symbolic]
  47. // CHECK:STDOUT: %pattern_type.98f: type = pattern_type type [concrete]
  48. // CHECK:STDOUT: %pattern_type.e6836e.1: type = pattern_type %T [symbolic]
  49. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete]
  50. // CHECK:STDOUT: %ImplicitAs.type.cc7: type = generic_interface_type @ImplicitAs [concrete]
  51. // CHECK:STDOUT: %ImplicitAs.generic: %ImplicitAs.type.cc7 = struct_value () [concrete]
  52. // CHECK:STDOUT: %Dest: type = symbolic_binding Dest, 0 [symbolic]
  53. // CHECK:STDOUT: %ImplicitAs.Convert.type.4c8ddd.1: type = fn_type @ImplicitAs.Convert, @ImplicitAs(%Dest) [symbolic]
  54. // CHECK:STDOUT: %ImplicitAs.Convert.e9f4dc.1: %ImplicitAs.Convert.type.4c8ddd.1 = struct_value () [symbolic]
  55. // CHECK:STDOUT: %ImplicitAs.assoc_type.8b5194.1: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  56. // CHECK:STDOUT: %ImplicitAs.type.2d9d4e.2: type = facet_type <@ImplicitAs, @ImplicitAs(%T)> [symbolic]
  57. // CHECK:STDOUT: %ImplicitAs.assoc_type.8b5194.2: type = assoc_entity_type @ImplicitAs, @ImplicitAs(%T) [symbolic]
  58. // CHECK:STDOUT: %assoc0.f64c6b.2: %ImplicitAs.assoc_type.8b5194.2 = assoc_entity element0, imports.%Core.import_ref.b91 [symbolic]
  59. // CHECK:STDOUT: %assoc0.7b6: %ImplicitAs.assoc_type.8b5194.1 = assoc_entity element0, imports.%Core.import_ref.d11 [symbolic]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  64. // CHECK:STDOUT: .Int = %Core.Int
  65. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  66. // CHECK:STDOUT: import Core//prelude
  67. // CHECK:STDOUT: import Core//prelude/...
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  70. // CHECK:STDOUT: %Core.ImplicitAs: %ImplicitAs.type.cc7 = import_ref Core//prelude/parts/as, ImplicitAs, loaded [concrete = constants.%ImplicitAs.generic]
  71. // CHECK:STDOUT: %Core.import_ref.b9c: @ImplicitAs.%ImplicitAs.assoc_type (%ImplicitAs.assoc_type.8b5194.1) = import_ref Core//prelude/parts/as, loc{{\d+_\d+}}, loaded [symbolic = @ImplicitAs.%assoc0 (constants.%assoc0.7b6)]
  72. // CHECK:STDOUT: %Core.import_ref.b91: @ImplicitAs.%ImplicitAs.Convert.type (%ImplicitAs.Convert.type.4c8ddd.1) = import_ref Core//prelude/parts/as, loc{{\d+_\d+}}, loaded [symbolic = @ImplicitAs.%ImplicitAs.Convert (constants.%ImplicitAs.Convert.e9f4dc.1)]
  73. // CHECK:STDOUT: %Core.import_ref.d11 = import_ref Core//prelude/parts/as, loc{{\d+_\d+}}, unloaded
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  78. // CHECK:STDOUT: .Core = imports.%Core
  79. // CHECK:STDOUT: .F = %F.decl
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %Core.import = import Core
  82. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  83. // CHECK:STDOUT: %a.patt: %pattern_type.7ce = value_binding_pattern a [concrete]
  84. // CHECK:STDOUT: %a.param_patt: %pattern_type.7ce = value_param_pattern %a.patt, call_param0 [concrete]
  85. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  86. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  87. // CHECK:STDOUT: } {
  88. // CHECK:STDOUT: %int_32.loc16_17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  89. // CHECK:STDOUT: %i32.loc16_17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  90. // CHECK:STDOUT: %a.param: %i32 = value_param call_param0
  91. // CHECK:STDOUT: %.loc16: type = splice_block %i32.loc16_9 [concrete = constants.%i32] {
  92. // CHECK:STDOUT: %int_32.loc16_9: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  93. // CHECK:STDOUT: %i32.loc16_9: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  94. // CHECK:STDOUT: }
  95. // CHECK:STDOUT: %a: %i32 = value_binding a, %a.param
  96. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  97. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: }
  100. // CHECK:STDOUT:
  101. // CHECK:STDOUT: fn @F(%a.param: %i32) -> %i32 {
  102. // CHECK:STDOUT: !entry:
  103. // CHECK:STDOUT: name_binding_decl {
  104. // CHECK:STDOUT: %T.patt: %pattern_type.98f = symbolic_binding_pattern T, 0 [concrete]
  105. // CHECK:STDOUT: }
  106. // CHECK:STDOUT: %int_32.loc17: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  107. // CHECK:STDOUT: %i32.loc17: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  108. // CHECK:STDOUT: %.Self: %type = symbolic_binding .Self [symbolic_self = constants.%.Self]
  109. // CHECK:STDOUT: %T: type = symbolic_binding T, 0, %i32.loc17 [symbolic = constants.%T]
  110. // CHECK:STDOUT: name_binding_decl {
  111. // CHECK:STDOUT: %x.patt: %pattern_type.e6836e.1 = value_binding_pattern x [concrete]
  112. // CHECK:STDOUT: }
  113. // CHECK:STDOUT: %int_5: Core.IntLiteral = int_value 5 [concrete = constants.%int_5]
  114. // CHECK:STDOUT: %T.ref: type = name_ref T, %T [symbolic = constants.%T]
  115. // CHECK:STDOUT: %ImplicitAs.type: type = facet_type <@ImplicitAs, @ImplicitAs(constants.%T)> [symbolic = constants.%ImplicitAs.type.2d9d4e.2]
  116. // CHECK:STDOUT: %.loc25_14.1: %ImplicitAs.assoc_type.8b5194.2 = specific_constant imports.%Core.import_ref.b9c, @ImplicitAs(constants.%T) [symbolic = constants.%assoc0.f64c6b.2]
  117. // CHECK:STDOUT: %Convert.ref: %ImplicitAs.assoc_type.8b5194.2 = name_ref Convert, %.loc25_14.1 [symbolic = constants.%assoc0.f64c6b.2]
  118. // CHECK:STDOUT: %.loc25_14.2: %T = converted %int_5, <error> [concrete = <error>]
  119. // CHECK:STDOUT: %x: %T = value_binding x, <error> [concrete = <error>]
  120. // CHECK:STDOUT: %x.ref: %T = name_ref x, %x [concrete = <error>]
  121. // CHECK:STDOUT: %.loc33: %i32 = converted %x.ref, <error> [concrete = <error>]
  122. // CHECK:STDOUT: return <error> to %return
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: