fail_deref_not_pointer.carbon 6.0 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` [DerefOfNonPointer]
  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` [ArrowOperatorOfNonPointer]
  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 `()` [DerefOfNonPointer]
  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 `()` [ArrowOperatorOfNonPointer]
  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 `{}` [DerefOfNonPointer]
  32. // CHECK:STDERR: *{};
  33. // CHECK:STDERR: ^
  34. // CHECK:STDERR:
  35. *{};
  36. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: error: cannot apply `->` operator to non-pointer type `{}` [ArrowOperatorOfNonPointer]
  37. // CHECK:STDERR: {}->foo;
  38. // CHECK:STDERR: ^~
  39. // CHECK:STDERR:
  40. {}->foo;
  41. }
  42. // CHECK:STDOUT: --- fail_deref_not_pointer.carbon
  43. // CHECK:STDOUT:
  44. // CHECK:STDOUT: constants {
  45. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  46. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  47. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  48. // CHECK:STDOUT: %Deref.type: type = fn_type @Deref [concrete]
  49. // CHECK:STDOUT: %Deref: %Deref.type = struct_value () [concrete]
  50. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  51. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  52. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  53. // CHECK:STDOUT: }
  54. // CHECK:STDOUT:
  55. // CHECK:STDOUT: imports {
  56. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  57. // CHECK:STDOUT: .Int = %Core.Int
  58. // CHECK:STDOUT: import Core//prelude
  59. // CHECK:STDOUT: import Core//prelude/...
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT: }
  62. // CHECK:STDOUT:
  63. // CHECK:STDOUT: file {
  64. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  65. // CHECK:STDOUT: .Core = imports.%Core
  66. // CHECK:STDOUT: .Deref = %Deref.decl
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.import = import Core
  69. // CHECK:STDOUT: %Deref.decl: %Deref.type = fn_decl @Deref [concrete = constants.%Deref] {
  70. // CHECK:STDOUT: %n.patt: %i32 = binding_pattern n
  71. // CHECK:STDOUT: %n.param_patt: %i32 = value_param_pattern %n.patt, call_param0
  72. // CHECK:STDOUT: } {
  73. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  74. // CHECK:STDOUT: %.loc11: type = splice_block %i32 [concrete = constants.%i32] {
  75. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  76. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  77. // CHECK:STDOUT: }
  78. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  79. // CHECK:STDOUT: }
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @Deref(%n.param_patt: %i32) {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: %n.ref.loc16: %i32 = name_ref n, %n
  85. // CHECK:STDOUT: %.loc16: ref <error> = deref %n.ref.loc16 [concrete = <error>]
  86. // CHECK:STDOUT: %n.ref.loc21: %i32 = name_ref n, %n
  87. // CHECK:STDOUT: %.loc21: ref <error> = deref %n.ref.loc21 [concrete = <error>]
  88. // CHECK:STDOUT: %foo.ref.loc21: <error> = name_ref foo, <error> [concrete = <error>]
  89. // CHECK:STDOUT: %.loc26_5.1: %empty_tuple.type = tuple_literal ()
  90. // CHECK:STDOUT: %empty_tuple.loc26: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  91. // CHECK:STDOUT: %.loc26_5.2: %empty_tuple.type = converted %.loc26_5.1, %empty_tuple.loc26 [concrete = constants.%empty_tuple]
  92. // CHECK:STDOUT: %.loc26_3: ref <error> = deref %.loc26_5.2 [concrete = <error>]
  93. // CHECK:STDOUT: %.loc31_4.1: %empty_tuple.type = tuple_literal ()
  94. // CHECK:STDOUT: %empty_tuple.loc31: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  95. // CHECK:STDOUT: %.loc31_4.2: %empty_tuple.type = converted %.loc31_4.1, %empty_tuple.loc31 [concrete = constants.%empty_tuple]
  96. // CHECK:STDOUT: %.loc31_5: ref <error> = deref %.loc31_4.2 [concrete = <error>]
  97. // CHECK:STDOUT: %foo.ref.loc31: <error> = name_ref foo, <error> [concrete = <error>]
  98. // CHECK:STDOUT: %.loc36_5.1: %empty_struct_type = struct_literal ()
  99. // CHECK:STDOUT: %empty_struct.loc36: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  100. // CHECK:STDOUT: %.loc36_5.2: %empty_struct_type = converted %.loc36_5.1, %empty_struct.loc36 [concrete = constants.%empty_struct]
  101. // CHECK:STDOUT: %.loc36_3: ref <error> = deref %.loc36_5.2 [concrete = <error>]
  102. // CHECK:STDOUT: %.loc41_4.1: %empty_struct_type = struct_literal ()
  103. // CHECK:STDOUT: %empty_struct.loc41: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  104. // CHECK:STDOUT: %.loc41_4.2: %empty_struct_type = converted %.loc41_4.1, %empty_struct.loc41 [concrete = constants.%empty_struct]
  105. // CHECK:STDOUT: %.loc41_5: ref <error> = deref %.loc41_4.2 [concrete = <error>]
  106. // CHECK:STDOUT: %foo.ref.loc41: <error> = name_ref foo, <error> [concrete = <error>]
  107. // CHECK:STDOUT: return
  108. // CHECK:STDOUT: }
  109. // CHECK:STDOUT: