fail_redundant_compound_access.carbon 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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/operators/builtin/fail_redundant_compound_access.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/operators/builtin/fail_redundant_compound_access.carbon
  10. fn F() -> i32 { return 0; }
  11. fn Main() {
  12. var a: i32 = 3;
  13. // CHECK:STDERR: fail_redundant_compound_access.carbon:[[@LINE+4]]:7: error: member name of type `i32` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase]
  14. // CHECK:STDERR: a = a.(a);
  15. // CHECK:STDERR: ^~~~~
  16. // CHECK:STDERR:
  17. a = a.(a);
  18. // CHECK:STDERR: fail_redundant_compound_access.carbon:[[@LINE+4]]:7: error: member name of type `<type of F>` in compound member access is not an instance member or an interface member [CompoundMemberAccessDoesNotUseBase]
  19. // CHECK:STDERR: a = a.(F)();
  20. // CHECK:STDERR: ^~~~~
  21. // CHECK:STDERR:
  22. a = a.(F)();
  23. }
  24. // CHECK:STDOUT: --- fail_redundant_compound_access.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  28. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  29. // CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
  30. // CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
  31. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [concrete]
  32. // CHECK:STDOUT: %ImplicitAs.type.205: type = facet_type <@ImplicitAs, @ImplicitAs(%i32)> [concrete]
  33. // CHECK:STDOUT: %Convert.type.1b6: type = fn_type @Convert.1, @ImplicitAs(%i32) [concrete]
  34. // CHECK:STDOUT: %ImplicitAs.impl_witness_table.a2f = impl_witness_table (imports.%Core.import_ref.a5b), @impl.4f9 [concrete]
  35. // CHECK:STDOUT: %ImplicitAs.impl_witness.c75: <witness> = impl_witness %ImplicitAs.impl_witness_table.a2f, @impl.4f9(%int_32) [concrete]
  36. // CHECK:STDOUT: %Convert.type.035: type = fn_type @Convert.2, @impl.4f9(%int_32) [concrete]
  37. // CHECK:STDOUT: %Convert.956: %Convert.type.035 = struct_value () [concrete]
  38. // CHECK:STDOUT: %ImplicitAs.facet: %ImplicitAs.type.205 = facet_value Core.IntLiteral, (%ImplicitAs.impl_witness.c75) [concrete]
  39. // CHECK:STDOUT: %.9c3: type = fn_type_with_self_type %Convert.type.1b6, %ImplicitAs.facet [concrete]
  40. // CHECK:STDOUT: %Convert.bound.d04: <bound method> = bound_method %int_0.5c6, %Convert.956 [concrete]
  41. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.956, @Convert.2(%int_32) [concrete]
  42. // CHECK:STDOUT: %bound_method.b6e: <bound method> = bound_method %int_0.5c6, %Convert.specific_fn [concrete]
  43. // CHECK:STDOUT: %int_0.6a9: %i32 = int_value 0 [concrete]
  44. // CHECK:STDOUT: %Main.type: type = fn_type @Main [concrete]
  45. // CHECK:STDOUT: %Main: %Main.type = struct_value () [concrete]
  46. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [concrete]
  47. // CHECK:STDOUT: %Convert.bound.b30: <bound method> = bound_method %int_3.1ba, %Convert.956 [concrete]
  48. // CHECK:STDOUT: %bound_method.047: <bound method> = bound_method %int_3.1ba, %Convert.specific_fn [concrete]
  49. // CHECK:STDOUT: %int_3.822: %i32 = int_value 3 [concrete]
  50. // CHECK:STDOUT: }
  51. // CHECK:STDOUT:
  52. // CHECK:STDOUT: imports {
  53. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  54. // CHECK:STDOUT: .Int = %Core.Int
  55. // CHECK:STDOUT: .ImplicitAs = %Core.ImplicitAs
  56. // CHECK:STDOUT: import Core//prelude
  57. // CHECK:STDOUT: import Core//prelude/...
  58. // CHECK:STDOUT: }
  59. // CHECK:STDOUT: }
  60. // CHECK:STDOUT:
  61. // CHECK:STDOUT: file {
  62. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  63. // CHECK:STDOUT: .Core = imports.%Core
  64. // CHECK:STDOUT: .F = %F.decl
  65. // CHECK:STDOUT: .Main = %Main.decl
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %Core.import = import Core
  68. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [concrete = constants.%F] {
  69. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  70. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, call_param0
  71. // CHECK:STDOUT: } {
  72. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  73. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  74. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param0
  75. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  76. // CHECK:STDOUT: }
  77. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [concrete = constants.%Main] {} {}
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @F() -> %i32 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [concrete = constants.%int_0.5c6]
  83. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  84. // CHECK:STDOUT: %bound_method.loc11_25.1: <bound method> = bound_method %int_0, %impl.elem0 [concrete = constants.%Convert.bound.d04]
  85. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  86. // CHECK:STDOUT: %bound_method.loc11_25.2: <bound method> = bound_method %int_0, %specific_fn [concrete = constants.%bound_method.b6e]
  87. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc11_25.2(%int_0) [concrete = constants.%int_0.6a9]
  88. // CHECK:STDOUT: %.loc11_25.1: %i32 = value_of_initializer %int.convert_checked [concrete = constants.%int_0.6a9]
  89. // CHECK:STDOUT: %.loc11_25.2: %i32 = converted %int_0, %.loc11_25.1 [concrete = constants.%int_0.6a9]
  90. // CHECK:STDOUT: return %.loc11_25.2
  91. // CHECK:STDOUT: }
  92. // CHECK:STDOUT:
  93. // CHECK:STDOUT: fn @Main() {
  94. // CHECK:STDOUT: !entry:
  95. // CHECK:STDOUT: name_binding_decl {
  96. // CHECK:STDOUT: %a.patt: %i32 = binding_pattern a
  97. // CHECK:STDOUT: %.loc14_3.1: %i32 = var_pattern %a.patt
  98. // CHECK:STDOUT: }
  99. // CHECK:STDOUT: %a.var: ref %i32 = var a
  100. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [concrete = constants.%int_3.1ba]
  101. // CHECK:STDOUT: %impl.elem0: %.9c3 = impl_witness_access constants.%ImplicitAs.impl_witness.c75, element0 [concrete = constants.%Convert.956]
  102. // CHECK:STDOUT: %bound_method.loc14_3.1: <bound method> = bound_method %int_3, %impl.elem0 [concrete = constants.%Convert.bound.b30]
  103. // CHECK:STDOUT: %specific_fn: <specific function> = specific_function %impl.elem0, @Convert.2(constants.%int_32) [concrete = constants.%Convert.specific_fn]
  104. // CHECK:STDOUT: %bound_method.loc14_3.2: <bound method> = bound_method %int_3, %specific_fn [concrete = constants.%bound_method.047]
  105. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %bound_method.loc14_3.2(%int_3) [concrete = constants.%int_3.822]
  106. // CHECK:STDOUT: %.loc14_3.2: init %i32 = converted %int_3, %int.convert_checked [concrete = constants.%int_3.822]
  107. // CHECK:STDOUT: assign %a.var, %.loc14_3.2
  108. // CHECK:STDOUT: %.loc14_10: type = splice_block %i32 [concrete = constants.%i32] {
  109. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  110. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  111. // CHECK:STDOUT: }
  112. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  113. // CHECK:STDOUT: %a.ref.loc19_3: ref %i32 = name_ref a, %a
  114. // CHECK:STDOUT: %a.ref.loc19_7: ref %i32 = name_ref a, %a
  115. // CHECK:STDOUT: %a.ref.loc19_10: ref %i32 = name_ref a, %a
  116. // CHECK:STDOUT: %.loc19: %i32 = bind_value %a.ref.loc19_10
  117. // CHECK:STDOUT: assign %a.ref.loc19_3, %.loc19
  118. // CHECK:STDOUT: %a.ref.loc24_3: ref %i32 = name_ref a, %a
  119. // CHECK:STDOUT: %a.ref.loc24_7: ref %i32 = name_ref a, %a
  120. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
  121. // CHECK:STDOUT: %F.call: init %i32 = call %F.ref()
  122. // CHECK:STDOUT: assign %a.ref.loc24_3, %F.call
  123. // CHECK:STDOUT: return
  124. // CHECK:STDOUT: }
  125. // CHECK:STDOUT: