fail_unknown_member.carbon 4.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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` [MemberNameNotFoundInScope]
  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 [template]
  25. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  26. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  27. // CHECK:STDOUT: %Class.elem: type = unbound_element_type %Class, %i32 [template]
  28. // CHECK:STDOUT: %struct_type.n: type = struct_type {.n: %i32} [template]
  29. // CHECK:STDOUT: %complete_type.54b: <witness> = complete_type_witness %struct_type.n [template]
  30. // CHECK:STDOUT: %G.type: type = fn_type @G [template]
  31. // CHECK:STDOUT: %G: %G.type = struct_value () [template]
  32. // CHECK:STDOUT: }
  33. // CHECK:STDOUT:
  34. // CHECK:STDOUT: imports {
  35. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  36. // CHECK:STDOUT: .Int = %import_ref.485
  37. // CHECK:STDOUT: import Core//prelude
  38. // CHECK:STDOUT: import Core//prelude/...
  39. // CHECK:STDOUT: }
  40. // CHECK:STDOUT: }
  41. // CHECK:STDOUT:
  42. // CHECK:STDOUT: file {
  43. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  44. // CHECK:STDOUT: .Core = imports.%Core
  45. // CHECK:STDOUT: .Class = %Class.decl
  46. // CHECK:STDOUT: .G = %G.decl
  47. // CHECK:STDOUT: }
  48. // CHECK:STDOUT: %Core.import = import Core
  49. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  50. // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {
  51. // CHECK:STDOUT: %c.patt: %Class = binding_pattern c
  52. // CHECK:STDOUT: %c.param_patt: %Class = value_param_pattern %c.patt, runtime_param0
  53. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  54. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param1
  55. // CHECK:STDOUT: } {
  56. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  57. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  58. // CHECK:STDOUT: %c.param: %Class = value_param runtime_param0
  59. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  60. // CHECK:STDOUT: %c: %Class = bind_name c, %c.param
  61. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param1
  62. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  63. // CHECK:STDOUT: }
  64. // CHECK:STDOUT: }
  65. // CHECK:STDOUT:
  66. // CHECK:STDOUT: class @Class {
  67. // CHECK:STDOUT: %.loc12_8: %Class.elem = field_decl n, element0 [template]
  68. // CHECK:STDOUT: name_binding_decl {
  69. // CHECK:STDOUT: %.loc12_3: %Class.elem = var_pattern %.loc12_8
  70. // CHECK:STDOUT: }
  71. // CHECK:STDOUT: %.var: ref %Class.elem = var <invalid>
  72. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %struct_type.n [template = constants.%complete_type.54b]
  73. // CHECK:STDOUT: complete_type_witness = %complete_type
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: !members:
  76. // CHECK:STDOUT: .Self = constants.%Class
  77. // CHECK:STDOUT: .n = %.loc12_8
  78. // CHECK:STDOUT: }
  79. // CHECK:STDOUT:
  80. // CHECK:STDOUT: fn @G(%c.param_patt: %Class) -> %i32 {
  81. // CHECK:STDOUT: !entry:
  82. // CHECK:STDOUT: %c.ref: %Class = name_ref c, %c
  83. // CHECK:STDOUT: %something.ref: <error> = name_ref something, <error> [template = <error>]
  84. // CHECK:STDOUT: return <error>
  85. // CHECK:STDOUT: }
  86. // CHECK:STDOUT: