mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 17:52:58 +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.
259 lines
11 KiB
Plaintext
259 lines
11 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/bool.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/if/basics.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/if/basics.carbon
|
|
|
|
// --- else.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn F() {}
|
|
fn G() {}
|
|
fn H() {}
|
|
|
|
//@dump-sem-ir-begin
|
|
fn If(b: bool) {
|
|
if (b) {
|
|
F();
|
|
} else {
|
|
G();
|
|
}
|
|
H();
|
|
}
|
|
//@dump-sem-ir-end
|
|
|
|
// --- no_else.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn F() {}
|
|
fn G() {}
|
|
|
|
//@dump-sem-ir-begin
|
|
fn If(b: bool) {
|
|
if (b) {
|
|
F();
|
|
}
|
|
G();
|
|
}
|
|
//@dump-sem-ir-end
|
|
|
|
// --- unreachable_fallthrough.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
//@dump-sem-ir-begin
|
|
fn If(b: bool) -> bool {
|
|
if (b) {
|
|
return false;
|
|
} else {
|
|
return true;
|
|
}
|
|
// Missing return here is OK.
|
|
}
|
|
//@dump-sem-ir-end
|
|
|
|
// --- fail_reachable_fallthrough.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn If1(b: bool) -> bool {
|
|
if (b) {
|
|
return false;
|
|
} else {
|
|
}
|
|
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+4]]:1: error: missing `return` at end of function with declared return type [MissingReturnStatement]
|
|
// CHECK:STDERR: }
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
}
|
|
|
|
fn If2(b: bool) -> bool {
|
|
if (b) {
|
|
} else {
|
|
return true;
|
|
}
|
|
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+4]]:1: error: missing `return` at end of function with declared return type [MissingReturnStatement]
|
|
// CHECK:STDERR: }
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
}
|
|
|
|
fn If3(b: bool) -> bool {
|
|
if (b) {
|
|
return false;
|
|
}
|
|
// CHECK:STDERR: fail_reachable_fallthrough.carbon:[[@LINE+4]]:1: error: missing `return` at end of function with declared return type [MissingReturnStatement]
|
|
// CHECK:STDERR: }
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
}
|
|
|
|
// --- fail_scope.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
fn VarScope(b: bool) -> bool {
|
|
if (b) {
|
|
var n: bool = true;
|
|
return n;
|
|
}
|
|
// CHECK:STDERR: fail_scope.carbon:[[@LINE+4]]:10: error: name `n` not found [NameNotFound]
|
|
// CHECK:STDERR: return n;
|
|
// CHECK:STDERR: ^
|
|
// CHECK:STDERR:
|
|
return n;
|
|
}
|
|
|
|
// CHECK:STDOUT: --- else.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
|
|
// CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %H.type: type = fn_type @H [concrete]
|
|
// CHECK:STDOUT: %H: %H.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
|
|
// CHECK:STDOUT: %If.type: type = fn_type @If [concrete]
|
|
// CHECK:STDOUT: %If: %If.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [concrete = constants.%If] {
|
|
// CHECK:STDOUT: %b.param_patt: %pattern_type.831 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %b.patt: %pattern_type.831 = at_binding_pattern b, %b.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %b.param: bool = value_param call_param0
|
|
// CHECK:STDOUT: %.loc8: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %b: bool = value_binding b, %b.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @If(%b.param: bool) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
|
|
// CHECK:STDOUT: if %b.ref br !if.then else br !if.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.then:
|
|
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
|
// CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
|
|
// CHECK:STDOUT: br !if.done
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.else:
|
|
// CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
|
|
// CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
|
|
// CHECK:STDOUT: br !if.done
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.done:
|
|
// CHECK:STDOUT: %H.ref: %H.type = name_ref H, file.%H.decl [concrete = constants.%H]
|
|
// CHECK:STDOUT: %H.call: init %empty_tuple.type = call %H.ref()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- no_else.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %F.type: type = fn_type @F [concrete]
|
|
// CHECK:STDOUT: %empty_tuple.type: type = tuple_type () [concrete]
|
|
// CHECK:STDOUT: %F: %F.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %G.type: type = fn_type @G [concrete]
|
|
// CHECK:STDOUT: %G: %G.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
|
|
// CHECK:STDOUT: %If.type: type = fn_type @If [concrete]
|
|
// CHECK:STDOUT: %If: %If.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [concrete = constants.%If] {
|
|
// CHECK:STDOUT: %b.param_patt: %pattern_type.831 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %b.patt: %pattern_type.831 = at_binding_pattern b, %b.param_patt [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %b.param: bool = value_param call_param0
|
|
// CHECK:STDOUT: %.loc7: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %b: bool = value_binding b, %b.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @If(%b.param: bool) {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
|
|
// CHECK:STDOUT: if %b.ref br !if.then else br !if.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.then:
|
|
// CHECK:STDOUT: %F.ref: %F.type = name_ref F, file.%F.decl [concrete = constants.%F]
|
|
// CHECK:STDOUT: %F.call: init %empty_tuple.type = call %F.ref()
|
|
// CHECK:STDOUT: br !if.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.else:
|
|
// CHECK:STDOUT: %G.ref: %G.type = name_ref G, file.%G.decl [concrete = constants.%G]
|
|
// CHECK:STDOUT: %G.call: init %empty_tuple.type = call %G.ref()
|
|
// CHECK:STDOUT: return
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: --- unreachable_fallthrough.carbon
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: constants {
|
|
// CHECK:STDOUT: %pattern_type.831: type = pattern_type bool [concrete]
|
|
// CHECK:STDOUT: %.f34: Core.Form = init_form bool [concrete]
|
|
// CHECK:STDOUT: %If.type: type = fn_type @If [concrete]
|
|
// CHECK:STDOUT: %If: %If.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %false: bool = bool_literal false [concrete]
|
|
// CHECK:STDOUT: %Copy.type: type = facet_type <@Copy> [concrete]
|
|
// CHECK:STDOUT: %Copy.impl_witness.bc7: <witness> = impl_witness imports.%Copy.impl_witness_table.aef [concrete]
|
|
// CHECK:STDOUT: %Copy.facet: %Copy.type = facet_value bool, (%Copy.impl_witness.bc7) [concrete]
|
|
// CHECK:STDOUT: %Copy.WithSelf.Op.type.5dd: type = fn_type @Copy.WithSelf.Op, @Copy.WithSelf(%Copy.facet) [concrete]
|
|
// CHECK:STDOUT: %.698: type = fn_type_with_self_type %Copy.WithSelf.Op.type.5dd, %Copy.facet [concrete]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op.type: type = fn_type @bool.as.Copy.impl.Op [concrete]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op: %bool.as.Copy.impl.Op.type = struct_value () [concrete]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op.bound.84b: <bound method> = bound_method %false, %bool.as.Copy.impl.Op [concrete]
|
|
// CHECK:STDOUT: %true: bool = bool_literal true [concrete]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op.bound.1b3: <bound method> = bound_method %true, %bool.as.Copy.impl.Op [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: imports {
|
|
// CHECK:STDOUT: %Core.import_ref.41e: %bool.as.Copy.impl.Op.type = import_ref Core//prelude/parts/copy, loc{{\d+_\d+}}, loaded [concrete = constants.%bool.as.Copy.impl.Op]
|
|
// CHECK:STDOUT: %Copy.impl_witness_table.aef = impl_witness_table (%Core.import_ref.41e), @bool.as.Copy.impl [concrete]
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: file {
|
|
// CHECK:STDOUT: %If.decl: %If.type = fn_decl @If [concrete = constants.%If] {
|
|
// CHECK:STDOUT: %b.param_patt: %pattern_type.831 = value_param_pattern [concrete]
|
|
// CHECK:STDOUT: %b.patt: %pattern_type.831 = at_binding_pattern b, %b.param_patt [concrete]
|
|
// CHECK:STDOUT: %return.param_patt: %pattern_type.831 = out_param_pattern [concrete]
|
|
// CHECK:STDOUT: %return.patt: %pattern_type.831 = return_slot_pattern %return.param_patt, %.loc4_19.1 [concrete]
|
|
// CHECK:STDOUT: } {
|
|
// CHECK:STDOUT: %.loc4_19.1: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %.loc4_19.2: Core.Form = init_form %.loc4_19.1 [concrete = constants.%.f34]
|
|
// CHECK:STDOUT: %b.param: bool = value_param call_param0
|
|
// CHECK:STDOUT: %.loc4_10: type = type_literal bool [concrete = bool]
|
|
// CHECK:STDOUT: %b: bool = value_binding b, %b.param
|
|
// CHECK:STDOUT: %return.param: ref bool = out_param call_param1
|
|
// CHECK:STDOUT: %return: ref bool = return_slot %return.param
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: fn @If(%b.param: bool) -> out %return.param: bool {
|
|
// CHECK:STDOUT: !entry:
|
|
// CHECK:STDOUT: %b.ref: bool = name_ref b, %b
|
|
// CHECK:STDOUT: if %b.ref br !if.then else br !if.else
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.then:
|
|
// CHECK:STDOUT: %false: bool = bool_literal false [concrete = constants.%false]
|
|
// CHECK:STDOUT: %impl.elem0.loc6: %.698 = impl_witness_access constants.%Copy.impl_witness.bc7, element0 [concrete = constants.%bool.as.Copy.impl.Op]
|
|
// CHECK:STDOUT: %bound_method.loc6: <bound method> = bound_method %false, %impl.elem0.loc6 [concrete = constants.%bool.as.Copy.impl.Op.bound.84b]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op.call.loc6: init bool = call %bound_method.loc6(%false) [concrete = constants.%false]
|
|
// CHECK:STDOUT: return %bool.as.Copy.impl.Op.call.loc6
|
|
// CHECK:STDOUT:
|
|
// CHECK:STDOUT: !if.else:
|
|
// CHECK:STDOUT: %true: bool = bool_literal true [concrete = constants.%true]
|
|
// CHECK:STDOUT: %impl.elem0.loc8: %.698 = impl_witness_access constants.%Copy.impl_witness.bc7, element0 [concrete = constants.%bool.as.Copy.impl.Op]
|
|
// CHECK:STDOUT: %bound_method.loc8: <bound method> = bound_method %true, %impl.elem0.loc8 [concrete = constants.%bool.as.Copy.impl.Op.bound.1b3]
|
|
// CHECK:STDOUT: %bool.as.Copy.impl.Op.call.loc8: init bool = call %bound_method.loc8(%true) [concrete = constants.%true]
|
|
// CHECK:STDOUT: return %bool.as.Copy.impl.Op.call.loc8
|
|
// CHECK:STDOUT: }
|
|
// CHECK:STDOUT:
|