mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-26 15:51:19 +00:00
When declaring a name such as `fn Ns.Class.F() { ... }`, enter the
scopes of `Ns` and `Ns.Class` as we form the name, and remain in those
non-lexical scopes until the end of the declaration.
When performing an unqualified lookup, look in any enclosing non-lexical
scopes in addition to looking into the lexical name table.
We now track a scope index with each lookup result in the lexical name
lookup table. This is used to determine whether a lexical or non-lexcial
result is the innermost result and whether a declared name is in the
same scope as some previous introduction of that name or in a nested
scope. For now, this could just be the index into the scope_stack, but
the intent is to also use this to detect names being declared after they
are first looked up, which requires the indexes to outlive their scopes,
so we use a persistent numbering of all scopes instead. The persistent
numbering also permits more invariant checking.
81 lines
2.2 KiB
Plaintext
81 lines
2.2 KiB
Plaintext
// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
|
|
// Exceptions. See /LICENSE for license information.
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
|
//
|
|
// AUTOUPDATE
|
|
|
|
class A;
|
|
|
|
class X {
|
|
// OK, a different A.
|
|
class A { class B; }
|
|
class A.B {}
|
|
}
|
|
|
|
class A { class B; }
|
|
|
|
class Y {
|
|
// CHECK:STDERR: fail_redeclaration_scope.carbon:[[@LINE+3]]:9: ERROR: Name `A` not found.
|
|
// CHECK:STDERR: class A.B {}
|
|
// CHECK:STDERR: ^
|
|
class A.B {}
|
|
}
|
|
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %.loc11: type = struct_type {}
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file "fail_redeclaration_scope.carbon" {
|
|
// CHECK:STDOUT: class_declaration @A.1, ()
|
|
// CHECK:STDOUT: %A: type = class_type @A.1
|
|
// CHECK:STDOUT: class_declaration @X, ()
|
|
// CHECK:STDOUT: %X: type = class_type @X
|
|
// CHECK:STDOUT: class_declaration @A.1, ()
|
|
// CHECK:STDOUT: class_declaration @Y, ()
|
|
// CHECK:STDOUT: %Y: type = class_type @Y
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @A.1 {
|
|
// CHECK:STDOUT: class_declaration @B.2, ()
|
|
// CHECK:STDOUT: %B: type = class_type @B.2
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .B = <unexpected instref 20>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @X {
|
|
// CHECK:STDOUT: class_declaration @A.2, ()
|
|
// CHECK:STDOUT: %A: type = class_type @A.2
|
|
// CHECK:STDOUT: class_declaration @B.1, ()
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .A = <unexpected instref 13>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @A.2 {
|
|
// CHECK:STDOUT: class_declaration @B.1, ()
|
|
// CHECK:STDOUT: %B: type = class_type @B.1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .B = <unexpected instref 15>
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @B.1 {
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @B.2;
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @Y {
|
|
// CHECK:STDOUT: class_declaration @.1, ()
|
|
// CHECK:STDOUT: %.loc21: type = class_type @.1
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @.1 {
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: }
|