fail_unknown_member.carbon 4.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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/class/fail_unknown_member.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_unknown_member.carbon
  10. class Class {
  11. var n: i32;
  12. }
  13. fn G(c: Class) -> i32 {
  14. // TODO: Mention the scope in which we looked for the name.
  15. // CHECK:STDERR: fail_unknown_member.carbon:[[@LINE+4]]:10: error: member name `something` not found in `Class` [MemberNameNotFoundInInstScope]
  16. // CHECK:STDERR: return c.something;
  17. // CHECK:STDERR: ^~~~~~~~~~~
  18. // CHECK:STDERR:
  19. return c.something;
  20. }
  21. // CHECK:STDOUT: --- fail_unknown_member.carbon
  22. // CHECK:STDOUT:
  23. // CHECK:STDOUT: constants {
  24. // CHECK:STDOUT: %Class: type = class_type @Class [concrete]
  25. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete]
  26. // CHECK:STDOUT: %Int.type: type = generic_class_type @Int [concrete]
  27. // CHECK:STDOUT: %Int.generic: %Int.type = struct_value () [concrete]
  28. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [concrete]
  29. // CHECK:STDOUT: %Class.elem: type = unbound_element_type %Class, %i32 [concrete]
  30. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete]
  31. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [concrete]
  32. // CHECK:STDOUT: %pattern_type.761: type = pattern_type %Class [concrete]
  33. // CHECK:STDOUT: %pattern_type.7ce: type = pattern_type %i32 [concrete]
  34. // CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
  35. // CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
  40. // CHECK:STDOUT: .Int = %Core.Int
  41. // CHECK:STDOUT: import Core//prelude
  42. // CHECK:STDOUT: import Core//prelude/...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: %Core.Int: %Int.type = import_ref Core//prelude/types/int, Int, loaded [concrete = constants.%Int.generic]
  45. // CHECK:STDOUT: }
  46. // CHECK:STDOUT:
  47. // CHECK:STDOUT: file {
  48. // CHECK:STDOUT: package: <namespace> = namespace [concrete] {
  49. // CHECK:STDOUT: .Core = imports.%Core
  50. // CHECK:STDOUT: .Class = %Class.decl
  51. // CHECK:STDOUT: .G = %G.decl
  52. // CHECK:STDOUT: }
  53. // CHECK:STDOUT: %Core.import = import Core
  54. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [concrete = constants.%Class] {} {}
  55. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [concrete = constants.%G] {
  56. // CHECK:STDOUT: %c.patt: %pattern_type.761 = binding_pattern c [concrete]
  57. // CHECK:STDOUT: %c.param_patt: %pattern_type.761 = value_param_pattern %c.patt, call_param0 [concrete]
  58. // CHECK:STDOUT: %return.patt: %pattern_type.7ce = return_slot_pattern [concrete]
  59. // CHECK:STDOUT: %return.param_patt: %pattern_type.7ce = out_param_pattern %return.patt, call_param1 [concrete]
  60. // CHECK:STDOUT: } {
  61. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [concrete = constants.%int_32]
  62. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [concrete = constants.%i32]
  63. // CHECK:STDOUT: %c.param: %Class = value_param call_param0
  64. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [concrete = constants.%Class]
  65. // CHECK:STDOUT: %c: %Class = bind_name c, %c.param
  66. // CHECK:STDOUT: %return.param: ref %i32 = out_param call_param1
  67. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  68. // CHECK:STDOUT: }
  69. // CHECK:STDOUT: }
  70. // CHECK:STDOUT:
  71. // CHECK:STDOUT: class @Class {
  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: %.loc12: %Class.elem = field_decl n, element0 [concrete]
  75. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [concrete = constants.%struct_type.n]
  76. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [concrete = constants.%complete_type.54b]
  77. // CHECK:STDOUT: complete_type_witness = %complete_type
  78. // CHECK:STDOUT:
  79. // CHECK:STDOUT: !members:
  80. // CHECK:STDOUT: .Self = constants.%Class
  81. // CHECK:STDOUT: .n = %.loc12
  82. // CHECK:STDOUT: .something = <poisoned>
  83. // CHECK:STDOUT: }
  84. // CHECK:STDOUT:
  85. // CHECK:STDOUT: fn @G(%c.param: %Class) -> %i32 {
  86. // CHECK:STDOUT: !entry:
  87. // CHECK:STDOUT: %c.ref: %Class = name_ref c, %c
  88. // CHECK:STDOUT: %something.ref: <error> = name_ref something, <error> [concrete = <error>]
  89. // CHECK:STDOUT: return <error>
  90. // CHECK:STDOUT: }
  91. // CHECK:STDOUT: