fail_collapse.carbon 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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/const/fail_collapse.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/const/fail_collapse.carbon
  10. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+4]]:9: warning: `const` applied repeatedly to the same type has no additional effect
  11. // CHECK:STDERR: fn G(p: const (const i32)**) -> i32** {
  12. // CHECK:STDERR: ^~~~~~~~~~~~~~~~~
  13. // CHECK:STDERR:
  14. fn G(p: const (const i32)**) -> i32** {
  15. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+6]]:3: error: cannot implicitly convert from `const i32**` to `i32**`
  16. // CHECK:STDERR: return p;
  17. // CHECK:STDERR: ^~~~~~~~~
  18. // CHECK:STDERR: fail_collapse.carbon:[[@LINE+3]]:3: note: type `const i32**` does not implement interface `ImplicitAs`
  19. // CHECK:STDERR: return p;
  20. // CHECK:STDERR: ^~~~~~~~~
  21. return p;
  22. }
  23. // CHECK:STDOUT: --- fail_collapse.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  27. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  28. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  29. // CHECK:STDOUT: %.2: type = const_type i32 [template]
  30. // CHECK:STDOUT: %.3: type = ptr_type %.2 [template]
  31. // CHECK:STDOUT: %.4: type = ptr_type %.3 [template]
  32. // CHECK:STDOUT: %.5: type = ptr_type i32 [template]
  33. // CHECK:STDOUT: %.6: type = ptr_type %.5 [template]
  34. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  35. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  36. // CHECK:STDOUT: %ImplicitAs.type: type = generic_interface_type @ImplicitAs [template]
  37. // CHECK:STDOUT: %ImplicitAs: %ImplicitAs.type = struct_value () [template]
  38. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic]
  39. // CHECK:STDOUT: %.7: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic]
  40. // CHECK:STDOUT: %Self.1: @ImplicitAs.%.1 (%.7) = bind_symbolic_name Self 1 [symbolic]
  41. // CHECK:STDOUT: %Self.2: %.7 = bind_symbolic_name Self 1 [symbolic]
  42. // CHECK:STDOUT: %Convert.type.1: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic]
  43. // CHECK:STDOUT: %Convert.1: %Convert.type.1 = struct_value () [symbolic]
  44. // CHECK:STDOUT: %.8: type = assoc_entity_type %.7, %Convert.type.1 [symbolic]
  45. // CHECK:STDOUT: %.9: %.8 = assoc_entity element0, imports.%import_ref.6 [symbolic]
  46. // CHECK:STDOUT: %.10: type = interface_type @ImplicitAs, @ImplicitAs(%.6) [template]
  47. // CHECK:STDOUT: %Convert.type.2: type = fn_type @Convert, @ImplicitAs(%.6) [template]
  48. // CHECK:STDOUT: %Convert.2: %Convert.type.2 = struct_value () [template]
  49. // CHECK:STDOUT: %.11: type = assoc_entity_type %.10, %Convert.type.2 [template]
  50. // CHECK:STDOUT: %.12: %.11 = assoc_entity element0, imports.%import_ref.6 [template]
  51. // CHECK:STDOUT: %.13: %.8 = assoc_entity element0, imports.%import_ref.7 [symbolic]
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT:
  54. // CHECK:STDOUT: imports {
  55. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  56. // CHECK:STDOUT: .Int32 = %import_ref.1
  57. // CHECK:STDOUT: .ImplicitAs = %import_ref.2
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/operators
  60. // CHECK:STDOUT: import Core//prelude/types
  61. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  62. // CHECK:STDOUT: import Core//prelude/operators/as
  63. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  64. // CHECK:STDOUT: import Core//prelude/operators/comparison
  65. // CHECK:STDOUT: import Core//prelude/types/bool
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %import_ref.1: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  68. // CHECK:STDOUT: %import_ref.2: %ImplicitAs.type = import_ref Core//prelude/operators/as, inst+40, loaded [template = constants.%ImplicitAs]
  69. // CHECK:STDOUT: %import_ref.3 = import_ref Core//prelude/operators/as, inst+45, unloaded
  70. // CHECK:STDOUT: %import_ref.4: @ImplicitAs.%.2 (%.8) = import_ref Core//prelude/operators/as, inst+63, loaded [symbolic = @ImplicitAs.%.3 (constants.%.13)]
  71. // CHECK:STDOUT: %import_ref.5 = import_ref Core//prelude/operators/as, inst+56, unloaded
  72. // CHECK:STDOUT: %import_ref.6 = import_ref Core//prelude/operators/as, inst+56, unloaded
  73. // CHECK:STDOUT: %import_ref.7 = import_ref Core//prelude/operators/as, inst+56, unloaded
  74. // CHECK:STDOUT: }
  75. // CHECK:STDOUT:
  76. // CHECK:STDOUT: file {
  77. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  78. // CHECK:STDOUT: .Core = imports.%Core
  79. // CHECK:STDOUT: .G = %G.decl
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: %Core.import = import Core
  82. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  83. // CHECK:STDOUT: %p.patt: %.4 = binding_pattern p
  84. // CHECK:STDOUT: } {
  85. // CHECK:STDOUT: %int.make_type_32.loc15_22: init type = call constants.%Int32() [template = i32]
  86. // CHECK:STDOUT: %.loc15_16.1: type = value_of_initializer %int.make_type_32.loc15_22 [template = i32]
  87. // CHECK:STDOUT: %.loc15_16.2: type = converted %int.make_type_32.loc15_22, %.loc15_16.1 [template = i32]
  88. // CHECK:STDOUT: %.loc15_16.3: type = const_type i32 [template = constants.%.2]
  89. // CHECK:STDOUT: %.loc15_9: type = const_type %.2 [template = constants.%.2]
  90. // CHECK:STDOUT: %.loc15_26: type = ptr_type %.2 [template = constants.%.3]
  91. // CHECK:STDOUT: %.loc15_27: type = ptr_type %.3 [template = constants.%.4]
  92. // CHECK:STDOUT: %p.param: %.4 = param p, runtime_param0
  93. // CHECK:STDOUT: %p: %.4 = bind_name p, %p.param
  94. // CHECK:STDOUT: %int.make_type_32.loc15_33: init type = call constants.%Int32() [template = i32]
  95. // CHECK:STDOUT: %.loc15_36.1: type = value_of_initializer %int.make_type_32.loc15_33 [template = i32]
  96. // CHECK:STDOUT: %.loc15_36.2: type = converted %int.make_type_32.loc15_33, %.loc15_36.1 [template = i32]
  97. // CHECK:STDOUT: %.loc15_36.3: type = ptr_type i32 [template = constants.%.5]
  98. // CHECK:STDOUT: %.loc15_37: type = ptr_type %.5 [template = constants.%.6]
  99. // CHECK:STDOUT: %return: ref %.6 = var <return slot>
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT: }
  102. // CHECK:STDOUT:
  103. // CHECK:STDOUT: generic interface @ImplicitAs(constants.%Dest: type) {
  104. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: !definition:
  107. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.7)]
  108. // CHECK:STDOUT: %Self: %.7 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  109. // CHECK:STDOUT: %Convert.type: type = fn_type @Convert, @ImplicitAs(%Dest) [symbolic = %Convert.type (constants.%Convert.type.1)]
  110. // CHECK:STDOUT: %Convert: @ImplicitAs.%Convert.type (%Convert.type.1) = struct_value () [symbolic = %Convert (constants.%Convert.1)]
  111. // CHECK:STDOUT: %.2: type = assoc_entity_type @ImplicitAs.%.1 (%.7), @ImplicitAs.%Convert.type (%Convert.type.1) [symbolic = %.2 (constants.%.8)]
  112. // CHECK:STDOUT: %.3: @ImplicitAs.%.2 (%.8) = assoc_entity element0, imports.%import_ref.6 [symbolic = %.3 (constants.%.9)]
  113. // CHECK:STDOUT:
  114. // CHECK:STDOUT: interface {
  115. // CHECK:STDOUT: !members:
  116. // CHECK:STDOUT: .Self = imports.%import_ref.3
  117. // CHECK:STDOUT: .Convert = imports.%import_ref.4
  118. // CHECK:STDOUT: witness = (imports.%import_ref.5)
  119. // CHECK:STDOUT: }
  120. // CHECK:STDOUT: }
  121. // CHECK:STDOUT:
  122. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  123. // CHECK:STDOUT:
  124. // CHECK:STDOUT: fn @G(%p: %.4) -> %.6 {
  125. // CHECK:STDOUT: !entry:
  126. // CHECK:STDOUT: %p.ref: %.4 = name_ref p, %p
  127. // CHECK:STDOUT: %.loc22_11.1: type = interface_type @ImplicitAs, @ImplicitAs(constants.%.6) [template = constants.%.10]
  128. // CHECK:STDOUT: %.loc22_11.2: %.11 = specific_constant imports.%import_ref.4, @ImplicitAs(constants.%.6) [template = constants.%.12]
  129. // CHECK:STDOUT: %Convert.ref: %.11 = name_ref Convert, %.loc22_11.2 [template = constants.%.12]
  130. // CHECK:STDOUT: %.loc22_11.3: %.6 = converted %p.ref, <error> [template = <error>]
  131. // CHECK:STDOUT: return <error>
  132. // CHECK:STDOUT: }
  133. // CHECK:STDOUT:
  134. // CHECK:STDOUT: generic fn @Convert(constants.%Dest: type, constants.%Self.1: @ImplicitAs.%.1 (%.7)) {
  135. // CHECK:STDOUT: %Dest: type = bind_symbolic_name Dest 0 [symbolic = %Dest (constants.%Dest)]
  136. // CHECK:STDOUT: %.1: type = interface_type @ImplicitAs, @ImplicitAs(%Dest) [symbolic = %.1 (constants.%.7)]
  137. // CHECK:STDOUT: %Self: %.7 = bind_symbolic_name Self 1 [symbolic = %Self (constants.%Self.2)]
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: fn[%self: @Convert.%Self (%Self.2)]() -> @Convert.%Dest (%Dest);
  140. // CHECK:STDOUT: }
  141. // CHECK:STDOUT:
  142. // CHECK:STDOUT: specific @ImplicitAs(constants.%Dest) {
  143. // CHECK:STDOUT: %Dest => constants.%Dest
  144. // CHECK:STDOUT: }
  145. // CHECK:STDOUT:
  146. // CHECK:STDOUT: specific @ImplicitAs(@ImplicitAs.%Dest) {
  147. // CHECK:STDOUT: %Dest => constants.%Dest
  148. // CHECK:STDOUT: }
  149. // CHECK:STDOUT:
  150. // CHECK:STDOUT: specific @ImplicitAs(@Convert.%Dest) {
  151. // CHECK:STDOUT: %Dest => constants.%Dest
  152. // CHECK:STDOUT: }
  153. // CHECK:STDOUT:
  154. // CHECK:STDOUT: specific @Convert(constants.%Dest, constants.%Self.1) {
  155. // CHECK:STDOUT: %Dest => constants.%Dest
  156. // CHECK:STDOUT: %.1 => constants.%.7
  157. // CHECK:STDOUT: %Self => constants.%Self.1
  158. // CHECK:STDOUT: }
  159. // CHECK:STDOUT:
  160. // CHECK:STDOUT: specific @ImplicitAs(constants.%.6) {
  161. // CHECK:STDOUT: %Dest => constants.%.6
  162. // CHECK:STDOUT:
  163. // CHECK:STDOUT: !definition:
  164. // CHECK:STDOUT: %.1 => constants.%.10
  165. // CHECK:STDOUT: %Self => constants.%Self.2
  166. // CHECK:STDOUT: %Convert.type => constants.%Convert.type.2
  167. // CHECK:STDOUT: %Convert => constants.%Convert.2
  168. // CHECK:STDOUT: %.2 => constants.%.11
  169. // CHECK:STDOUT: %.3 => constants.%.12
  170. // CHECK:STDOUT: }
  171. // CHECK:STDOUT: