fail_deref_not_pointer.carbon 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. // INCLUDE-FILE: toolchain/testing/testdata/min_prelude/int.carbon
  6. // TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
  7. // EXTRA-ARGS: --dump-sem-ir-ranges=if-present
  8. //
  9. // AUTOUPDATE
  10. // TIP: To test this file alone, run:
  11. // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/pointer/fail_deref_not_pointer.carbon
  12. // TIP: To dump output, run:
  13. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/pointer/fail_deref_not_pointer.carbon
  14. fn Deref(n: i32) {
  15. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `i32` [DerefOfNonPointer]
  16. // CHECK:STDERR: *n;
  17. // CHECK:STDERR: ^
  18. // CHECK:STDERR:
  19. *n;
  20. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:4: error: cannot apply `->` operator to non-pointer type `i32` [ArrowOperatorOfNonPointer]
  21. // CHECK:STDERR: n->foo;
  22. // CHECK:STDERR: ^~
  23. // CHECK:STDERR:
  24. n->foo;
  25. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `()` [DerefOfNonPointer]
  26. // CHECK:STDERR: *();
  27. // CHECK:STDERR: ^
  28. // CHECK:STDERR:
  29. *();
  30. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: error: cannot apply `->` operator to non-pointer type `()` [ArrowOperatorOfNonPointer]
  31. // CHECK:STDERR: ()->foo;
  32. // CHECK:STDERR: ^~
  33. // CHECK:STDERR:
  34. ()->foo;
  35. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:3: error: cannot dereference operand of non-pointer type `{}` [DerefOfNonPointer]
  36. // CHECK:STDERR: *{};
  37. // CHECK:STDERR: ^
  38. // CHECK:STDERR:
  39. *{};
  40. // CHECK:STDERR: fail_deref_not_pointer.carbon:[[@LINE+4]]:5: error: cannot apply `->` operator to non-pointer type `{}` [ArrowOperatorOfNonPointer]
  41. // CHECK:STDERR: {}->foo;
  42. // CHECK:STDERR: ^~
  43. // CHECK:STDERR:
  44. {}->foo;
  45. }
  46. // CHECK:STDOUT: --- fail_deref_not_pointer.carbon
  47. // CHECK:STDOUT:
  48. // CHECK:STDOUT: constants {
  49. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  50. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  51. // CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
  52. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  53. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  54. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  55. // CHECK:STDOUT: %Deref.type: type = fn_type @Deref [concrete]
  56. // CHECK:STDOUT: %Deref: %Deref.type = struct_value () [concrete]
  57. // CHECK:STDOUT: %empty_tuple: %empty_tuple.type = tuple_value () [concrete]
  58. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
  59. // CHECK:STDOUT: %empty_struct: %empty_struct_type = struct_value () [concrete]
  60. // CHECK:STDOUT: }
  61. // CHECK:STDOUT:
  62. // CHECK:STDOUT: imports {
  63. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  64. // CHECK:STDOUT: .Int = %Core.Int
  65. // CHECK:STDOUT: import Core//prelude
  66. // CHECK:STDOUT: import Core//prelude/...
  67. // CHECK:STDOUT: }
  68. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/parts/int, Int, loaded [concrete = constants.%Int.generic]
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: file {
  72. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  73. // CHECK:STDOUT: .Core = imports.%Core
  74. // CHECK:STDOUT: .Deref = %Deref.decl
  75. // CHECK:STDOUT: }
  76. // CHECK:STDOUT: %Core.import = import Core
  77. // CHECK:STDOUT: %Deref.decl: %Deref.type = fn_decl @Deref [concrete = constants.%Deref] {
  78. // CHECK:STDOUT: %n.patt: %pattern_type.7ce = binding_pattern n [concrete]
  79. // CHECK:STDOUT: %n.param_patt: %pattern_type.7ce = value_param_pattern %n.patt, call_param0 [concrete]
  80. // CHECK:STDOUT: } {
  81. // CHECK:STDOUT: %n.param: %i32 = value_param call_param0
  82. // CHECK:STDOUT: %.loc15: type = splice_block %i32 [concrete = constants.%i32] {
  83. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  84. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: %n: %i32 = bind_name n, %n.param
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: }
  89. // CHECK:STDOUT:
  90. // CHECK:STDOUT: fn @Deref(%n.param: %i32) {
  91. // CHECK:STDOUT: !entry:
  92. // CHECK:STDOUT: %n.ref.loc20: %i32 = name_ref n, %n
  93. // CHECK:STDOUT: %.loc20: ref <error> = deref %n.ref.loc20 [concrete = <error>]
  94. // CHECK:STDOUT: %n.ref.loc25: %i32 = name_ref n, %n
  95. // CHECK:STDOUT: %.loc25: ref <error> = deref %n.ref.loc25 [concrete = <error>]
  96. // CHECK:STDOUT: %foo.ref.loc25: <error> = name_ref foo, <error> [concrete = <error>]
  97. // CHECK:STDOUT: %.loc30_5.1: %empty_tuple.type = tuple_literal ()
  98. // CHECK:STDOUT: %empty_tuple.loc30: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  99. // CHECK:STDOUT: %.loc30_5.2: %empty_tuple.type = converted %.loc30_5.1, %empty_tuple.loc30 [concrete = constants.%empty_tuple]
  100. // CHECK:STDOUT: %.loc30_3: ref <error> = deref %.loc30_5.2 [concrete = <error>]
  101. // CHECK:STDOUT: %.loc35_4.1: %empty_tuple.type = tuple_literal ()
  102. // CHECK:STDOUT: %empty_tuple.loc35: %empty_tuple.type = tuple_value () [concrete = constants.%empty_tuple]
  103. // CHECK:STDOUT: %.loc35_4.2: %empty_tuple.type = converted %.loc35_4.1, %empty_tuple.loc35 [concrete = constants.%empty_tuple]
  104. // CHECK:STDOUT: %.loc35_5: ref <error> = deref %.loc35_4.2 [concrete = <error>]
  105. // CHECK:STDOUT: %foo.ref.loc35: <error> = name_ref foo, <error> [concrete = <error>]
  106. // CHECK:STDOUT: %.loc40_5.1: %empty_struct_type = struct_literal ()
  107. // CHECK:STDOUT: %empty_struct.loc40: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  108. // CHECK:STDOUT: %.loc40_5.2: %empty_struct_type = converted %.loc40_5.1, %empty_struct.loc40 [concrete = constants.%empty_struct]
  109. // CHECK:STDOUT: %.loc40_3: ref <error> = deref %.loc40_5.2 [concrete = <error>]
  110. // CHECK:STDOUT: %.loc45_4.1: %empty_struct_type = struct_literal ()
  111. // CHECK:STDOUT: %empty_struct.loc45: %empty_struct_type = struct_value () [concrete = constants.%empty_struct]
  112. // CHECK:STDOUT: %.loc45_4.2: %empty_struct_type = converted %.loc45_4.1, %empty_struct.loc45 [concrete = constants.%empty_struct]
  113. // CHECK:STDOUT: %.loc45_5: ref <error> = deref %.loc45_4.2 [concrete = <error>]
  114. // CHECK:STDOUT: %foo.ref.loc45: <error> = name_ref foo, <error> [concrete = <error>]
  115. // CHECK:STDOUT: return
  116. // CHECK:STDOUT: }
  117. // CHECK:STDOUT: