fail_deref_not_pointer.carbon 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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/pointer/fail_deref_not_pointer.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_not_pointer.carbon
  10. fn Deref(n: i32) {
  11. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: ERROR: Cannot dereference operand of non-pointer type `i32`.
  12. // CHECK:STDERR: *n;
  13. // CHECK:STDERR: ^
  14. // CHECK:STDERR:
  15. *n;
  16. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:4: ERROR: Cannot apply `->` operator to non-pointer type `i32`.
  17. // CHECK:STDERR: n->foo;
  18. // CHECK:STDERR: ^~
  19. // CHECK:STDERR:
  20. n->foo;
  21. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: ERROR: Cannot dereference operand of non-pointer type `()`.
  22. // CHECK:STDERR: *();
  23. // CHECK:STDERR: ^
  24. // CHECK:STDERR:
  25. *();
  26. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: ERROR: Cannot apply `->` operator to non-pointer type `()`.
  27. // CHECK:STDERR: ()->foo;
  28. // CHECK:STDERR: ^~
  29. // CHECK:STDERR:
  30. ()->foo;
  31. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: ERROR: Cannot dereference operand of non-pointer type `{}`.
  32. // CHECK:STDERR: *{};
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR:
  35. *{};
  36. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+3]]:5: ERROR: Cannot apply `->` operator to non-pointer type `{}`.
  37. // CHECK:STDERR: {}->foo;
  38. // CHECK:STDERR: ^~
  39. {}->foo;
  40. }
  41. // CHECK:STDOUT: --- fail_deref_not_pointer.carbon
  42. // CHECK:STDOUT:
  43. // CHECK:STDOUT: constants {
  44. // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
  45. // CHECK:STDOUT: %.1: type = tuple_type () [template]
  46. // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
  47. // CHECK:STDOUT: %Deref.type: type = fn_type @Deref [template]
  48. // CHECK:STDOUT: %Deref: %Deref.type = struct_value () [template]
  49. // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
  50. // CHECK:STDOUT: %.2: type = struct_type {} [template]
  51. // CHECK:STDOUT: %struct: %.2 = struct_value () [template]
  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
  57. // CHECK:STDOUT: import Core//prelude
  58. // CHECK:STDOUT: import Core//prelude/operators
  59. // CHECK:STDOUT: import Core//prelude/types
  60. // CHECK:STDOUT: import Core//prelude/operators/arithmetic
  61. // CHECK:STDOUT: import Core//prelude/operators/bitwise
  62. // CHECK:STDOUT: import Core//prelude/operators/comparison
  63. // CHECK:STDOUT: import Core//prelude/types/bool
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude/types, inst+4, loaded [template = constants.%Int32]
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT:
  68. // CHECK:STDOUT: file {
  69. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  70. // CHECK:STDOUT: .Core = imports.%Core
  71. // CHECK:STDOUT: .Deref = %Deref.decl
  72. // CHECK:STDOUT: }
  73. // CHECK:STDOUT: %Core.import = import Core
  74. // CHECK:STDOUT: %Deref.decl: %Deref.type = fn_decl @Deref [template = constants.%Deref] {
  75. // CHECK:STDOUT: %int.make_type_32: init type = call constants.%Int32() [template = i32]
  76. // CHECK:STDOUT: %.loc11_13.1: type = value_of_initializer %int.make_type_32 [template = i32]
  77. // CHECK:STDOUT: %.loc11_13.2: type = converted %int.make_type_32, %.loc11_13.1 [template = i32]
  78. // CHECK:STDOUT: %n.loc11_10.1: i32 = param n
  79. // CHECK:STDOUT: @Deref.%n: i32 = bind_name n, %n.loc11_10.1
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT: }
  82. // CHECK:STDOUT:
  83. // CHECK:STDOUT: fn @Int32() -> type = "int.make_type_32";
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @Deref(%n: i32) {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %n.ref.loc16: i32 = name_ref n, %n
  88. // CHECK:STDOUT: %.loc16: ref <error> = deref %n.ref.loc16
  89. // CHECK:STDOUT: %n.ref.loc21: i32 = name_ref n, %n
  90. // CHECK:STDOUT: %.loc21: ref <error> = deref %n.ref.loc21
  91. // CHECK:STDOUT: %.loc26_5.1: %.1 = tuple_literal ()
  92. // CHECK:STDOUT: %tuple.loc26: %.1 = tuple_value () [template = constants.%tuple]
  93. // CHECK:STDOUT: %.loc26_5.2: %.1 = converted %.loc26_5.1, %tuple.loc26 [template = constants.%tuple]
  94. // CHECK:STDOUT: %.loc26_3: ref <error> = deref %.loc26_5.2
  95. // CHECK:STDOUT: %.loc31_4.1: %.1 = tuple_literal ()
  96. // CHECK:STDOUT: %tuple.loc31: %.1 = tuple_value () [template = constants.%tuple]
  97. // CHECK:STDOUT: %.loc31_4.2: %.1 = converted %.loc31_4.1, %tuple.loc31 [template = constants.%tuple]
  98. // CHECK:STDOUT: %.loc31_5: ref <error> = deref %.loc31_4.2
  99. // CHECK:STDOUT: %.loc36_5.1: %.2 = struct_literal ()
  100. // CHECK:STDOUT: %struct.loc36: %.2 = struct_value () [template = constants.%struct]
  101. // CHECK:STDOUT: %.loc36_5.2: %.2 = converted %.loc36_5.1, %struct.loc36 [template = constants.%struct]
  102. // CHECK:STDOUT: %.loc36_3: ref <error> = deref %.loc36_5.2
  103. // CHECK:STDOUT: %.loc40_4.1: %.2 = struct_literal ()
  104. // CHECK:STDOUT: %struct.loc40: %.2 = struct_value () [template = constants.%struct]
  105. // CHECK:STDOUT: %.loc40_4.2: %.2 = converted %.loc40_4.1, %struct.loc40 [template = constants.%struct]
  106. // CHECK:STDOUT: %.loc40_5: ref <error> = deref %.loc40_4.2
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: