mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 12:00:09 +01:00
Fixes link failures when referencing a symbol involving a fingerprint from a different package. Previously we included the `Namespace`'s `import_id` as part of its fingerprint, which caused local and imported namespaces to get different fingerprints. We now store the `import_id` on the `NameScope` instead of on the `Namespace` inst to avoid this problem. Also, when we reach a package-level `NameScopeId`, consistently fingerprint it as a (package name, library name) pair. Previously the fingerprinting depended on whether it was imported or not, as an imported `NameScopeId` had a parent scope (the current package). We need to include the library name here so that private entities with the same name in different libraries have different fingerprints.
244 lines
13 KiB
Plaintext
244 lines
13 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
|
|
//
|
|
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
|
|
// TODO: Add ranges and switch to "--dump-sem-ir-ranges=only".
|
|
// EXTRA-ARGS: --dump-sem-ir-ranges=if-present
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/inheritance/base_method_shadow.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/inheritance/base_method_shadow.carbon
|
|
|
|
base class A {
|
|
fn F[ref self: Self]();
|
|
}
|
|
|
|
base class B {
|
|
extend base: A;
|
|
fn F[ref self: Self]();
|
|
}
|
|
|
|
class C {
|
|
extend base: B;
|
|
fn F[ref self: Self]();
|
|
}
|
|
|
|
class D {
|
|
extend base: B;
|
|
}
|
|
|
|
fn Call(a: A*, b: B*, c: C*, d: D*) {
|
|
(*a).F();
|
|
(*b).F();
|
|
(*c).F();
|
|
(*d).F();
|
|
}
|
|
|
|
// CHECK:STDOUT: --- base_method_shadow.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %A: type = class_type @A [concrete]
|
|
// CHECK:STDOUT: %pattern_type.a07: type = pattern_type %A [concrete]
|
|
// CHECK:STDOUT: %A.F.type: type = fn_type @A.F [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %A.F: %A.F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %empty_struct_type: type = struct_type {} [concrete]
|
|
// CHECK:STDOUT: %complete_type.357: <witness> = complete_type_witness %empty_struct_type [concrete]
|
|
// CHECK:STDOUT: %B: type = class_type @B [concrete]
|
|
// CHECK:STDOUT: %B.elem: type = unbound_element_type %B, %A [concrete]
|
|
// CHECK:STDOUT: %pattern_type.e90: type = pattern_type %B [concrete]
|
|
// CHECK:STDOUT: %B.F.type: type = fn_type @B.F [concrete]
|
|
// CHECK:STDOUT: %B.F: %B.F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %struct_type.base.61f: type = struct_type {.base: %A} [concrete]
|
|
// CHECK:STDOUT: %complete_type.2a7: <witness> = complete_type_witness %struct_type.base.61f [concrete]
|
|
// CHECK:STDOUT: %C: type = class_type @C [concrete]
|
|
// CHECK:STDOUT: %C.elem: type = unbound_element_type %C, %B [concrete]
|
|
// CHECK:STDOUT: %pattern_type.d7b: type = pattern_type %C [concrete]
|
|
// CHECK:STDOUT: %C.F.type: type = fn_type @C.F [concrete]
|
|
// CHECK:STDOUT: %C.F: %C.F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %struct_type.base.60e: type = struct_type {.base: %B} [concrete]
|
|
// CHECK:STDOUT: %complete_type.15d: <witness> = complete_type_witness %struct_type.base.60e [concrete]
|
|
// CHECK:STDOUT: %D: type = class_type @D [concrete]
|
|
// CHECK:STDOUT: %D.elem: type = unbound_element_type %D, %B [concrete]
|
|
// CHECK:STDOUT: %ptr.fe7: type = ptr_type %A [concrete]
|
|
// CHECK:STDOUT: %pattern_type.b00: type = pattern_type %ptr.fe7 [concrete]
|
|
// CHECK:STDOUT: %ptr.e4c: type = ptr_type %B [concrete]
|
|
// CHECK:STDOUT: %pattern_type.383: type = pattern_type %ptr.e4c [concrete]
|
|
// CHECK:STDOUT: %ptr.e38: type = ptr_type %C [concrete]
|
|
// CHECK:STDOUT: %pattern_type.19f: type = pattern_type %ptr.e38 [concrete]
|
|
// CHECK:STDOUT: %ptr.30b: type = ptr_type %D [concrete]
|
|
// CHECK:STDOUT: %pattern_type.290: type = pattern_type %ptr.30b [concrete]
|
|
// CHECK:STDOUT: %Call.type: type = fn_type @Call [concrete]
|
|
// CHECK:STDOUT: %Call: %Call.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [concrete] {
|
|
// CHECK:STDOUT: import Core//prelude
|
|
// CHECK:STDOUT: import Core//prelude/...
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: package: <namespace> = namespace [concrete] {
|
|
// CHECK:STDOUT: .Core = imports.%Core
|
|
// CHECK:STDOUT: .A = %A.decl
|
|
// CHECK:STDOUT: .B = %B.decl
|
|
// CHECK:STDOUT: .C = %C.decl
|
|
// CHECK:STDOUT: .D = %D.decl
|
|
// CHECK:STDOUT: .Call = %Call.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %Core.import = import Core
|
|
// CHECK:STDOUT: %A.decl: type = class_decl @A [concrete = constants.%A] {} {}
|
|
// CHECK:STDOUT: %B.decl: type = class_decl @B [concrete = constants.%B] {} {}
|
|
// CHECK:STDOUT: %C.decl: type = class_decl @C [concrete = constants.%C] {} {}
|
|
// CHECK:STDOUT: %D.decl: type = class_decl @D [concrete = constants.%D] {} {}
|
|
// CHECK:STDOUT: %Call.decl: %Call.type = fn_decl @Call [concrete = constants.%Call] {
|
|
// CHECK:STDOUT: %a.param_patt: %pattern_type.b00 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %a.patt: %pattern_type.b00 = at_binding_pattern a, %a.param_patt [concrete]
|
|
// CHECK:STDOUT: %b.param_patt: %pattern_type.383 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %b.patt: %pattern_type.383 = at_binding_pattern b, %b.param_patt [concrete]
|
|
// CHECK:STDOUT: %c.param_patt: %pattern_type.19f = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %c.patt: %pattern_type.19f = at_binding_pattern c, %c.param_patt [concrete]
|
|
// CHECK:STDOUT: %d.param_patt: %pattern_type.290 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %d.patt: %pattern_type.290 = at_binding_pattern d, %d.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %a.param: %ptr.fe7 = value_param call_param0
|
|
// CHECK:STDOUT: %.loc33_13: type = splice_block %ptr.loc33_13 [concrete = constants.%ptr.fe7] {
|
|
// CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
|
|
// CHECK:STDOUT: %ptr.loc33_13: type = ptr_type %A.ref [concrete = constants.%ptr.fe7]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %a: %ptr.fe7 = value_binding a, %a.param
|
|
// CHECK:STDOUT: %b.param: %ptr.e4c = value_param call_param1
|
|
// CHECK:STDOUT: %.loc33_20: type = splice_block %ptr.loc33_20 [concrete = constants.%ptr.e4c] {
|
|
// CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
|
|
// CHECK:STDOUT: %ptr.loc33_20: type = ptr_type %B.ref [concrete = constants.%ptr.e4c]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %b: %ptr.e4c = value_binding b, %b.param
|
|
// CHECK:STDOUT: %c.param: %ptr.e38 = value_param call_param2
|
|
// CHECK:STDOUT: %.loc33_27: type = splice_block %ptr.loc33_27 [concrete = constants.%ptr.e38] {
|
|
// CHECK:STDOUT: %C.ref: type = name_ref C, file.%C.decl [concrete = constants.%C]
|
|
// CHECK:STDOUT: %ptr.loc33_27: type = ptr_type %C.ref [concrete = constants.%ptr.e38]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %c: %ptr.e38 = value_binding c, %c.param
|
|
// CHECK:STDOUT: %d.param: %ptr.30b = value_param call_param3
|
|
// CHECK:STDOUT: %.loc33_34: type = splice_block %ptr.loc33_34 [concrete = constants.%ptr.30b] {
|
|
// CHECK:STDOUT: %D.ref: type = name_ref D, file.%D.decl [concrete = constants.%D]
|
|
// CHECK:STDOUT: %ptr.loc33_34: type = ptr_type %D.ref [concrete = constants.%ptr.30b]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %d: %ptr.30b = value_binding d, %d.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @A {
|
|
// CHECK:STDOUT: %A.F.decl: %A.F.type = fn_decl @A.F [concrete = constants.%A.F] {
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type.a07 = ref_param_pattern [concrete]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type.a07 = at_binding_pattern self, %self.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: ref %A = ref_param call_param0
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%A [concrete = constants.%A]
|
|
// CHECK:STDOUT: %self: ref %A = ref_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%empty_struct_type [concrete = constants.%complete_type.357]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%A
|
|
// CHECK:STDOUT: .F = %A.F.decl
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @B {
|
|
// CHECK:STDOUT: %A.ref: type = name_ref A, file.%A.decl [concrete = constants.%A]
|
|
// CHECK:STDOUT: %.loc20: %B.elem = base_decl %A.ref, element0 [concrete]
|
|
// CHECK:STDOUT: %B.F.decl: %B.F.type = fn_decl @B.F [concrete = constants.%B.F] {
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type.e90 = ref_param_pattern [concrete]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type.e90 = at_binding_pattern self, %self.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: ref %B = ref_param call_param0
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%B [concrete = constants.%B]
|
|
// CHECK:STDOUT: %self: ref %B = ref_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base.61f [concrete = constants.%complete_type.2a7]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%B
|
|
// CHECK:STDOUT: .A = <poisoned>
|
|
// CHECK:STDOUT: .base = %.loc20
|
|
// CHECK:STDOUT: .F = %B.F.decl
|
|
// CHECK:STDOUT: extend %A.ref
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @C {
|
|
// CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
|
|
// CHECK:STDOUT: %.loc25: %C.elem = base_decl %B.ref, element0 [concrete]
|
|
// CHECK:STDOUT: %C.F.decl: %C.F.type = fn_decl @C.F [concrete = constants.%C.F] {
|
|
// CHECK:STDOUT: %self.param_patt: %pattern_type.d7b = ref_param_pattern [concrete]
|
|
// CHECK:STDOUT: %self.patt: %pattern_type.d7b = at_binding_pattern self, %self.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %self.param: ref %C = ref_param call_param0
|
|
// CHECK:STDOUT: %Self.ref: type = name_ref Self, constants.%C [concrete = constants.%C]
|
|
// CHECK:STDOUT: %self: ref %C = ref_binding self, %self.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base.60e [concrete = constants.%complete_type.15d]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%C
|
|
// CHECK:STDOUT: .B = <poisoned>
|
|
// CHECK:STDOUT: .base = %.loc25
|
|
// CHECK:STDOUT: .F = %C.F.decl
|
|
// CHECK:STDOUT: extend %B.ref
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: class @D {
|
|
// CHECK:STDOUT: %B.ref: type = name_ref B, file.%B.decl [concrete = constants.%B]
|
|
// CHECK:STDOUT: %.loc30: %D.elem = base_decl %B.ref, element0 [concrete]
|
|
// CHECK:STDOUT: %complete_type: <witness> = complete_type_witness constants.%struct_type.base.60e [concrete = constants.%complete_type.15d]
|
|
// CHECK:STDOUT: complete_type_witness = %complete_type
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !members:
|
|
// CHECK:STDOUT: .Self = constants.%D
|
|
// CHECK:STDOUT: .B = <poisoned>
|
|
// CHECK:STDOUT: .base = %.loc30
|
|
// CHECK:STDOUT: .F = <poisoned>
|
|
// CHECK:STDOUT: extend %B.ref
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @A.F(%self.param: ref %A);
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @B.F(%self.param: ref %B);
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @C.F(%self.param: ref %C);
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @Call(%a.param: %ptr.fe7, %b.param: %ptr.e4c, %c.param: %ptr.e38, %d.param: %ptr.30b) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %a.ref: %ptr.fe7 = name_ref a, %a
|
|
// CHECK:STDOUT: %.loc34: ref %A = deref %a.ref
|
|
// CHECK:STDOUT: %F.ref.loc34: %A.F.type = name_ref F, @A.%A.F.decl [concrete = constants.%A.F]
|
|
// CHECK:STDOUT: %A.F.bound: <bound method> = bound_method %.loc34, %F.ref.loc34
|
|
// CHECK:STDOUT: %A.F.call: init %empty_tuple.type = call %A.F.bound(%.loc34)
|
|
// CHECK:STDOUT: %b.ref: %ptr.e4c = name_ref b, %b
|
|
// CHECK:STDOUT: %.loc35: ref %B = deref %b.ref
|
|
// CHECK:STDOUT: %F.ref.loc35: %B.F.type = name_ref F, @B.%B.F.decl [concrete = constants.%B.F]
|
|
// CHECK:STDOUT: %B.F.bound.loc35: <bound method> = bound_method %.loc35, %F.ref.loc35
|
|
// CHECK:STDOUT: %B.F.call.loc35: init %empty_tuple.type = call %B.F.bound.loc35(%.loc35)
|
|
// CHECK:STDOUT: %c.ref: %ptr.e38 = name_ref c, %c
|
|
// CHECK:STDOUT: %.loc36: ref %C = deref %c.ref
|
|
// CHECK:STDOUT: %F.ref.loc36: %C.F.type = name_ref F, @C.%C.F.decl [concrete = constants.%C.F]
|
|
// CHECK:STDOUT: %C.F.bound: <bound method> = bound_method %.loc36, %F.ref.loc36
|
|
// CHECK:STDOUT: %C.F.call: init %empty_tuple.type = call %C.F.bound(%.loc36)
|
|
// CHECK:STDOUT: %d.ref: %ptr.30b = name_ref d, %d
|
|
// CHECK:STDOUT: %.loc37_4.1: ref %D = deref %d.ref
|
|
// CHECK:STDOUT: %F.ref.loc37: %B.F.type = name_ref F, @B.%B.F.decl [concrete = constants.%B.F]
|
|
// CHECK:STDOUT: %B.F.bound.loc37: <bound method> = bound_method %.loc37_4.1, %F.ref.loc37
|
|
// CHECK:STDOUT: %.loc37_4.2: ref %B = class_element_access %.loc37_4.1, element0
|
|
// CHECK:STDOUT: %.loc37_4.3: ref %B = converted %.loc37_4.1, %.loc37_4.2
|
|
// CHECK:STDOUT: %B.F.call.loc37: init %empty_tuple.type = call %B.F.bound.loc37(%.loc37_4.3)
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|