Add Self to the name scope for a class. (#3736)

Rather than just adding `Self` to the lexical scope, add it to the
class's name scope so that it is visible in later lexical scopes for the
same class -- in particular, for out-of-line definitions of members.
Also switch some tests in `check/testdata/class` over to making
idiomatic use of `Self` both inside a class and out-of-line, now that it
works more consistently.

Note that this does not permit using `Class.Self`, but only because we
don't yet support keyword names after `.` at all. If that changed, one
could use `Class.Self` to redundantly refer to `Class`. Whether we allow
that is left to a future decision.
This commit is contained in:
Richard Smith
2024-02-29 21:33:47 +00:00
committed by GitHub
parent a6f4752a7b
commit 67d5446b03
81 changed files with 535 additions and 193 deletions
@@ -55,6 +55,7 @@ fn D.C.F() {}
// CHECK:STDOUT: %C.decl = class_decl @C {} [template = constants.%C]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%B
// CHECK:STDOUT: .F = %F
// CHECK:STDOUT: .C = %C.decl
// CHECK:STDOUT: }
@@ -63,6 +64,7 @@ fn D.C.F() {}
// CHECK:STDOUT: %F: <function> = fn_decl @F.2 {} [template]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%C
// CHECK:STDOUT: .F = %F
// CHECK:STDOUT: }
// CHECK:STDOUT:
@@ -71,6 +73,7 @@ fn D.C.F() {}
// CHECK:STDOUT: %.loc16: <unbound element of class D> = base_decl B, element0 [template]
// CHECK:STDOUT:
// CHECK:STDOUT: !members:
// CHECK:STDOUT: .Self = constants.%D
// CHECK:STDOUT: .base = %.loc16
// CHECK:STDOUT: .F = file.%F
// CHECK:STDOUT: extend name_scope1