fail_member_of_let.carbon 4.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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_member_of_let.carbon
  8. // TIP: To dump output, run:
  9. // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/fail_member_of_let.carbon
  10. class Class {
  11. fn F() -> i32;
  12. }
  13. // TODO: Use `:!` here once it is available.
  14. let T: type = Class;
  15. // The class name is required to be written in the same way as in the class
  16. // declaration. An expression that evaluates to the class name is not accepted.
  17. // CHECK:STDERR: fail_member_of_let.carbon:[[@LINE+6]]:4: error: name qualifiers are only allowed for entities that provide a scope [QualifiedNameInNonScope]
  18. // CHECK:STDERR: fn T.F() {}
  19. // CHECK:STDERR: ^
  20. // CHECK:STDERR: fail_member_of_let.carbon:[[@LINE-7]]:5: note: referenced non-scope entity declared here [QualifiedNameNonScopeEntity]
  21. // CHECK:STDERR: let T: type = Class;
  22. // CHECK:STDERR: ^
  23. fn T.F() {}
  24. // CHECK:STDOUT: --- fail_member_of_let.carbon
  25. // CHECK:STDOUT:
  26. // CHECK:STDOUT: constants {
  27. // CHECK:STDOUT: %Class: type = class_type @Class [template]
  28. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template]
  29. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(%int_32) [template]
  30. // CHECK:STDOUT: %F.type: type = fn_type @F [template]
  31. // CHECK:STDOUT: %F: %F.type = struct_value () [template]
  32. // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
  33. // CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [template]
  34. // CHECK:STDOUT: %.type: type = fn_type @.1 [template]
  35. // CHECK:STDOUT: %.d85: %.type = struct_value () [template]
  36. // CHECK:STDOUT: }
  37. // CHECK:STDOUT:
  38. // CHECK:STDOUT: imports {
  39. // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
  40. // CHECK:STDOUT: .Int = %import_ref.485
  41. // CHECK:STDOUT: import Core//prelude
  42. // CHECK:STDOUT: import Core//prelude/...
  43. // CHECK:STDOUT: }
  44. // CHECK:STDOUT: }
  45. // CHECK:STDOUT:
  46. // CHECK:STDOUT: file {
  47. // CHECK:STDOUT: package: <namespace> = namespace [template] {
  48. // CHECK:STDOUT: .Core = imports.%Core
  49. // CHECK:STDOUT: .Class = %Class.decl
  50. // CHECK:STDOUT: .T = @__global_init.%T
  51. // CHECK:STDOUT: }
  52. // CHECK:STDOUT: %Core.import = import Core
  53. // CHECK:STDOUT: %Class.decl: type = class_decl @Class [template = constants.%Class] {} {}
  54. // CHECK:STDOUT: %.decl: %.type = fn_decl @.1 [template = constants.%.d85] {} {}
  55. // CHECK:STDOUT: }
  56. // CHECK:STDOUT:
  57. // CHECK:STDOUT: class @Class {
  58. // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {
  59. // CHECK:STDOUT: %return.patt: %i32 = return_slot_pattern
  60. // CHECK:STDOUT: %return.param_patt: %i32 = out_param_pattern %return.patt, runtime_param0
  61. // CHECK:STDOUT: } {
  62. // CHECK:STDOUT: %int_32: Core.IntLiteral = int_value 32 [template = constants.%int_32]
  63. // CHECK:STDOUT: %i32: type = class_type @Int, @Int(constants.%int_32) [template = constants.%i32]
  64. // CHECK:STDOUT: %return.param: ref %i32 = out_param runtime_param0
  65. // CHECK:STDOUT: %return: ref %i32 = return_slot %return.param
  66. // CHECK:STDOUT: }
  67. // CHECK:STDOUT: %complete_type: <witness> = complete_type_witness %empty_struct_type [template = constants.%complete_type.357]
  68. // CHECK:STDOUT: complete_type_witness = %complete_type
  69. // CHECK:STDOUT:
  70. // CHECK:STDOUT: !members:
  71. // CHECK:STDOUT: .Self = constants.%Class
  72. // CHECK:STDOUT: .F = %F.decl
  73. // CHECK:STDOUT: }
  74. // CHECK:STDOUT:
  75. // CHECK:STDOUT: fn @F() -> %i32;
  76. // CHECK:STDOUT:
  77. // CHECK:STDOUT: fn @.1() {
  78. // CHECK:STDOUT: !entry:
  79. // CHECK:STDOUT: return
  80. // CHECK:STDOUT: }
  81. // CHECK:STDOUT:
  82. // CHECK:STDOUT: fn @__global_init() {
  83. // CHECK:STDOUT: !entry:
  84. // CHECK:STDOUT: %Class.ref: type = name_ref Class, file.%Class.decl [template = constants.%Class]
  85. // CHECK:STDOUT: %T: type = bind_name T, %Class.ref
  86. // CHECK:STDOUT: return
  87. // CHECK:STDOUT: }
  88. // CHECK:STDOUT: