fail_redundant_compound_access.carbon 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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+3]]: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. a = a.(F)();
  22. }
  23. // CHECK:STDOUT: --- fail_redundant_compound_access.carbon
  24. // CHECK:STDOUT:
  25. // CHECK:STDOUT: constants {
  26. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  27. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  28. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  29. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  30. // CHECK:STDOUT: %int_0.5c6: Core.IntLiteral = int_value 0 [template]
  31. // CHECK:STDOUT: %Convert.type.cd1: type = fn_type @Convert.1, @ImplicitAs(%i32) [template]
  32. // CHECK:STDOUT: %impl_witness.5b0: <witness> = impl_witness (imports.%import_ref.723), @impl.1(%int_32) [template]
  33. // CHECK:STDOUT: %Convert.type.466: type = fn_type @Convert.2, @impl.1(%int_32) [template]
  34. // CHECK:STDOUT: %Convert.925: %Convert.type.466 = struct_value () [template]
  35. // CHECK:STDOUT: %Convert.bound.b41: <bound method> = bound_method %int_0.5c6, %Convert.925 [template]
  36. // CHECK:STDOUT: %Convert.specific_fn.c35: <specific function> = specific_function %Convert.bound.b41, @Convert.2(%int_32) [template]
  37. // CHECK:STDOUT: %int_0.f61: %i32 = int_value 0 [template]
  38. // CHECK:STDOUT: %Main.type: type = fn_type @Main [template]
  39. // CHECK:STDOUT: %Main: %Main.type = struct_value () [template]
  40. // CHECK:STDOUT: %int_3.1ba: Core.IntLiteral = int_value 3 [template]
  41. // CHECK:STDOUT: %Convert.bound.0db: <bound method> = bound_method %int_3.1ba, %Convert.925 [template]
  42. // CHECK:STDOUT: %Convert.specific_fn.456: <specific function> = specific_function %Convert.bound.0db, @Convert.2(%int_32) [template]
  43. // CHECK:STDOUT: %int_3.25b: %i32 = int_value 3 [template]
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: imports {
  47. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  48. // CHECK:STDOUT: .Int = %import_ref.187
  49. // CHECK:STDOUT: .ImplicitAs = %import_ref.a69
  50. // CHECK:STDOUT: import Core//prelude
  51. // CHECK:STDOUT: import Core//prelude/...
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: file {
  56. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  57. // CHECK:STDOUT: .Core = imports.%Core
  58. // CHECK:STDOUT: .F = %F.decl
  59. // CHECK:STDOUT: .Main = %Main.decl
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: %Core.import = import Core
  62. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  63. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  64. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  65. // CHECK:STDOUT: } {
  66. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  67. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  68. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  69. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %Main.decl: %Main.type = fn_decl @Main [template = constants.%Main] {} {}
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT:
  74. // CHECK:STDOUT: fn @F() -> %i32 {
  75. // CHECK:STDOUT: !entry:
  76. // CHECK:STDOUT: %int_0: Core.IntLiteral = int_value 0 [template = constants.%int_0.5c6]
  77. // CHECK:STDOUT: %impl.elem0: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  78. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_0, %impl.elem0 [template = constants.%Convert.bound.b41]
  79. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.c35]
  80. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_0) [template = constants.%int_0.f61]
  81. // CHECK:STDOUT: %.loc11_25.1: %i32 = value_of_initializer %int.convert_checked [template = constants.%int_0.f61]
  82. // CHECK:STDOUT: %.loc11_25.2: %i32 = converted %int_0, %.loc11_25.1 [template = constants.%int_0.f61]
  83. // CHECK:STDOUT: return %.loc11_25.2
  84. // CHECK:STDOUT: }
  85. // CHECK:STDOUT:
  86. // CHECK:STDOUT: fn @Main() {
  87. // CHECK:STDOUT: !entry:
  88. // CHECK:STDOUT: %a.var: ref %i32 = var a
  89. // CHECK:STDOUT: %a: ref %i32 = bind_name a, %a.var
  90. // CHECK:STDOUT: %int_3: Core.IntLiteral = int_value 3 [template = constants.%int_3.1ba]
  91. // CHECK:STDOUT: %impl.elem0: %Convert.type.cd1 = impl_witness_access constants.%impl_witness.5b0, element0 [template = constants.%Convert.925]
  92. // CHECK:STDOUT: %Convert.bound: <bound method> = bound_method %int_3, %impl.elem0 [template = constants.%Convert.bound.0db]
  93. // CHECK:STDOUT: %Convert.specific_fn: <specific function> = specific_function %Convert.bound, @Convert.2(constants.%int_32) [template = constants.%Convert.specific_fn.456]
  94. // CHECK:STDOUT: %int.convert_checked: init %i32 = call %Convert.specific_fn(%int_3) [template = constants.%int_3.25b]
  95. // CHECK:STDOUT: %.loc14: init %i32 = converted %int_3, %int.convert_checked [template = constants.%int_3.25b]
  96. // CHECK:STDOUT: assign %a.var, %.loc14
  97. // CHECK:STDOUT: %a.ref.loc19_3: ref %i32 = name_ref a, %a
  98. // CHECK:STDOUT: %a.ref.loc19_7: ref %i32 = name_ref a, %a
  99. // CHECK:STDOUT: %a.ref.loc19_10: ref %i32 = name_ref a, %a
  100. // CHECK:STDOUT: %.loc19: %i32 = bind_value %a.ref.loc19_10
  101. // CHECK:STDOUT: assign %a.ref.loc19_3, %.loc19
  102. // CHECK:STDOUT: %a.ref.loc23_3: ref %i32 = name_ref a, %a
  103. // CHECK:STDOUT: %a.ref.loc23_7: ref %i32 = name_ref a, %a
  104. // CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [template = constants.%F]
  105. // CHECK:STDOUT: %F.call: init %i32 = call %F.ref()
  106. // CHECK:STDOUT: assign %a.ref.loc23_3, %F.call
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: