fail_member_lookup.carbon 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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/interface/no_prelude/fail_member_lookup.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/interface/no_prelude/fail_member_lookup.carbon
  10. interface Interface {
  11. fn F();
  12. let T:! type;
  13. }
  14. fn F() {
  15. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:3: error: value of type `<associated entity in Interface>` is not callable [CallToNonCallable]
  16. // CHECK:STDERR: Interface.F();
  17. // CHECK:STDERR: ^~~~~~~~~~~~~
  18. // CHECK:STDERR:
  19. Interface.F();
  20. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:10: error: `Core.ImplicitAs` implicitly referenced here, but package `Core` not found [CoreNotFound]
  21. // CHECK:STDERR: var v: Interface.T;
  22. // CHECK:STDERR: ^~~~~~~~~~~
  23. // CHECK:STDERR:
  24. var v: Interface.T;
  25. }
  26. interface Different {}
  27. // CHECK:STDERR: fail_member_lookup.carbon:[[@LINE+4]]:24: error: cannot access member of interface `Interface` in type `Different` that does not implement that interface [MissingImplInMemberAccess]
  28. // CHECK:STDERR: fn G(U:! Different) -> U.(Interface.T);
  29. // CHECK:STDERR: ^~~~~~~~~~~~~~~
  30. // CHECK:STDERR:
  31. fn G(U:! Different) -> U.(Interface.T);
  32. // CHECK:STDOUT: --- fail_member_lookup.carbon
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: constants {
  35. // CHECK:STDOUT: %Interface.type: type = facet_type <@Interface> [template]
  36. // CHECK:STDOUT: %Self.719: %Interface.type = bind_symbolic_name Self, 0 [symbolic]
  37. // CHECK:STDOUT: %F.type.1ad: type = fn_type @F.1 [template]
  38. // CHECK:STDOUT: %F.5d3: %F.type.1ad = struct_value () [template]
  39. // CHECK:STDOUT: %Interface.assoc_type: type = assoc_entity_type %Interface.type [template]
  40. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, @Interface.%F.decl [template]
  41. // CHECK:STDOUT: %assoc1: %Interface.assoc_type = assoc_entity element1, @Interface.%T [template]
  42. // CHECK:STDOUT: %F.type.b25: type = fn_type @F.2 [template]
  43. // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [template]
  44. // CHECK:STDOUT: %Different.type: type = facet_type <@Different> [template]
  45. // CHECK:STDOUT: %Self.e7f: %Different.type = bind_symbolic_name Self, 0 [symbolic]
  46. // CHECK:STDOUT: %U: %Different.type = bind_symbolic_name U, 0 [symbolic]
  47. // CHECK:STDOUT: %U.patt: %Different.type = symbolic_binding_pattern U, 0 [symbolic]
  48. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  49. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: file {
  53. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  54. // CHECK:STDOUT: .Interface = %Interface.decl
  55. // CHECK:STDOUT: .F = %F.decl
  56. // CHECK:STDOUT: .Different = %Different.decl
  57. // CHECK:STDOUT: .G = %G.decl
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: %Interface.decl: type = interface_decl @Interface [template = constants.%Interface.type] {} {}
  60. // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.2 [template = constants.%F.c41] {} {}
  61. // CHECK:STDOUT: %Different.decl: type = interface_decl @Different [template = constants.%Different.type] {} {}
  62. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  63. // CHECK:STDOUT: %U.patt.loc37_6.1: %Different.type = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc37_6.2 (constants.%U.patt)]
  64. // CHECK:STDOUT: %U.param_patt: %Different.type = value_param_pattern %U.patt.loc37_6.1, runtime_param<none> [symbolic = %U.patt.loc37_6.2 (constants.%U.patt)]
  65. // CHECK:STDOUT: %return.patt: <error> = return_slot_pattern
  66. // CHECK:STDOUT: %return.param_patt: <error> = out_param_pattern %return.patt, runtime_param0
  67. // CHECK:STDOUT: } {
  68. // CHECK:STDOUT: %U.ref: %Different.type = name_ref U, %U.loc37_6.1 [symbolic = %U.loc37_6.2 (constants.%U)]
  69. // CHECK:STDOUT: %Interface.ref: type = name_ref Interface, file.%Interface.decl [template = constants.%Interface.type]
  70. // CHECK:STDOUT: %T.ref: %Interface.assoc_type = name_ref T, @T.%assoc1 [template = constants.%assoc1]
  71. // CHECK:STDOUT: %U.param: %Different.type = value_param runtime_param<none>
  72. // CHECK:STDOUT: %Different.ref: type = name_ref Different, file.%Different.decl [template = constants.%Different.type]
  73. // CHECK:STDOUT: %U.loc37_6.1: %Different.type = bind_symbolic_name U, 0, %U.param [symbolic = %U.loc37_6.2 (constants.%U)]
  74. // CHECK:STDOUT: %return.param: ref <error> = out_param runtime_param0
  75. // CHECK:STDOUT: %return: ref <error> = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: interface @Interface {
  80. // CHECK:STDOUT: %Self: %Interface.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.719]
  81. // CHECK:STDOUT: %F.decl: %F.type.1ad = fn_decl @F.1 [template = constants.%F.5d3] {} {}
  82. // CHECK:STDOUT: %assoc0: %Interface.assoc_type = assoc_entity element0, %F.decl [template = constants.%assoc0]
  83. // CHECK:STDOUT: %T: type = assoc_const_decl @T [template] {
  84. // CHECK:STDOUT: %assoc1: %Interface.assoc_type = assoc_entity element1, @Interface.%T [template = constants.%assoc1]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT:
  87. // CHECK:STDOUT: !members:
  88. // CHECK:STDOUT: .Self = %Self
  89. // CHECK:STDOUT: .F = %assoc0
  90. // CHECK:STDOUT: .T = @T.%assoc1
  91. // CHECK:STDOUT: witness = (%F.decl, %T)
  92. // CHECK:STDOUT: }
  93. // CHECK:STDOUT:
  94. // CHECK:STDOUT: interface @Different {
  95. // CHECK:STDOUT: %Self: %Different.type = bind_symbolic_name Self, 0 [symbolic = constants.%Self.e7f]
  96. // CHECK:STDOUT:
  97. // CHECK:STDOUT: !members:
  98. // CHECK:STDOUT: .Self = %Self
  99. // CHECK:STDOUT: witness = ()
  100. // CHECK:STDOUT: }
  101. // CHECK:STDOUT:
  102. // CHECK:STDOUT: generic assoc_const @T(@Interface.%Self: %Interface.type) {
  103. // CHECK:STDOUT: assoc_const T:! type;
  104. // CHECK:STDOUT: }
  105. // CHECK:STDOUT:
  106. // CHECK:STDOUT: generic fn @F.1(@Interface.%Self: %Interface.type) {
  107. // CHECK:STDOUT: fn();
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT:
  110. // CHECK:STDOUT: fn @F.2() {
  111. // CHECK:STDOUT: !entry:
  112. // CHECK:STDOUT: %Interface.ref.loc22: type = name_ref Interface, file.%Interface.decl [template = constants.%Interface.type]
  113. // CHECK:STDOUT: %F.ref: %Interface.assoc_type = name_ref F, @Interface.%assoc0 [template = constants.%assoc0]
  114. // CHECK:STDOUT: name_binding_decl {
  115. // CHECK:STDOUT: %v.patt: <error> = binding_pattern v
  116. // CHECK:STDOUT: %.loc28_3: <error> = var_pattern %v.patt
  117. // CHECK:STDOUT: }
  118. // CHECK:STDOUT: %v.var: ref <error> = var v
  119. // CHECK:STDOUT: %.1: <error> = splice_block <error> [template = <error>] {
  120. // CHECK:STDOUT: %Interface.ref.loc28: type = name_ref Interface, file.%Interface.decl [template = constants.%Interface.type]
  121. // CHECK:STDOUT: %T.ref: %Interface.assoc_type = name_ref T, @T.%assoc1 [template = constants.%assoc1]
  122. // CHECK:STDOUT: %.loc28_19: type = converted %T.ref, <error> [template = <error>]
  123. // CHECK:STDOUT: }
  124. // CHECK:STDOUT: %v: <error> = bind_name v, <error>
  125. // CHECK:STDOUT: return
  126. // CHECK:STDOUT: }
  127. // CHECK:STDOUT:
  128. // CHECK:STDOUT: generic fn @G(%U.loc37_6.1: %Different.type) {
  129. // CHECK:STDOUT: %U.loc37_6.2: %Different.type = bind_symbolic_name U, 0 [symbolic = %U.loc37_6.2 (constants.%U)]
  130. // CHECK:STDOUT: %U.patt.loc37_6.2: %Different.type = symbolic_binding_pattern U, 0 [symbolic = %U.patt.loc37_6.2 (constants.%U.patt)]
  131. // CHECK:STDOUT:
  132. // CHECK:STDOUT: fn(%U.param_patt: %Different.type) -> <error>;
  133. // CHECK:STDOUT: }
  134. // CHECK:STDOUT:
  135. // CHECK:STDOUT: specific @F.1(constants.%Self.719) {}
  136. // CHECK:STDOUT:
  137. // CHECK:STDOUT: specific @T(constants.%Self.719) {}
  138. // CHECK:STDOUT:
  139. // CHECK:STDOUT: specific @G(constants.%U) {
  140. // CHECK:STDOUT: %U.loc37_6.2 => constants.%U
  141. // CHECK:STDOUT: %U.patt.loc37_6.2 => constants.%U
  142. // CHECK:STDOUT: }
  143. // CHECK:STDOUT: