// 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 // TIP: To test this file alone, run: // TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/class/cross_package_import.carbon // TIP: To dump output, run: // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/class/cross_package_import.carbon // ============================================================================ // Setup files // ============================================================================ // --- other_define.carbon package Other library "[[@TEST_NAME]]"; class C {} // --- other_extern.carbon package Other library "[[@TEST_NAME]]"; extern class C; // --- other_conflict.carbon package Other library "[[@TEST_NAME]]"; fn C() {} // ============================================================================ // Test files // ============================================================================ // --- define.carbon library "[[@TEST_NAME]]"; import Other library "other_define"; var c: Other.C = {}; // --- fail_extern.carbon library "[[@TEST_NAME]]"; import Other library "other_extern"; // CHECK:STDERR: fail_extern.carbon:[[@LINE+8]]:8: error: binding pattern has incomplete type `C` in name binding declaration [IncompleteTypeInBindingDecl] // CHECK:STDERR: var c: Other.C = {}; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: fail_extern.carbon:[[@LINE-5]]:1: in import [InImport] // CHECK:STDERR: other_extern.carbon:4:1: note: class was forward declared here [ClassForwardDeclaredHere] // CHECK:STDERR: extern class C; // CHECK:STDERR: ^~~~~~~~~~~~~~~ // CHECK:STDERR: var c: Other.C = {}; // --- fail_todo_merge_define_extern.carbon library "[[@TEST_NAME]]"; // CHECK:STDERR: fail_todo_merge_define_extern.carbon:[[@LINE+8]]:1: in import [InImport] // CHECK:STDERR: other_extern.carbon:4:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: extern class C; // CHECK:STDERR: ^~~~~~~~~~~~~~~ // CHECK:STDERR: fail_todo_merge_define_extern.carbon:[[@LINE+4]]:1: in import [InImport] // CHECK:STDERR: other_define.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: class C {} // CHECK:STDERR: ^~~~~~~~~ import Other library "other_define"; import Other library "other_extern"; // CHECK:STDERR: fail_todo_merge_define_extern.carbon:[[@LINE+4]]:8: note: in name lookup for `C` [InNameLookup] // CHECK:STDERR: var c: Other.C = {}; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: var c: Other.C = {}; // --- fail_conflict.carbon library "[[@TEST_NAME]]"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+8]]:1: in import [InImport] // CHECK:STDERR: other_conflict.carbon:4:1: error: duplicate name being declared in the same scope [NameDeclDuplicate] // CHECK:STDERR: fn C() {} // CHECK:STDERR: ^~~~~~~~ // CHECK:STDERR: fail_conflict.carbon:[[@LINE+4]]:1: in import [InImport] // CHECK:STDERR: other_define.carbon:4:1: note: name is previously declared here [NameDeclPrevious] // CHECK:STDERR: class C {} // CHECK:STDERR: ^~~~~~~~~ import Other library "other_define"; import Other library "other_conflict"; // CHECK:STDERR: fail_conflict.carbon:[[@LINE+4]]:8: note: in name lookup for `C` [InNameLookup] // CHECK:STDERR: var c: Other.C = {}; // CHECK:STDERR: ^~~~~~~ // CHECK:STDERR: var c: Other.C = {}; // CHECK:STDOUT: --- other_define.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .C = %C.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C { // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template = constants.%complete_type] // CHECK:STDOUT: complete_type_witness = %complete_type // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = constants.%C // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- other_extern.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .C = %C.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %C.decl: type = class_decl @C [template = constants.%C] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C; // CHECK:STDOUT: // CHECK:STDOUT: --- other_conflict.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C.type: type = fn_type @C [template] // CHECK:STDOUT: %C: %C.type = struct_value () [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .C = %C.decl // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %C.decl: %C.type = fn_decl @C [template = constants.%C] {} {} // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @C() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- define.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: %C.val: %C = struct_value () [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other: = namespace file.%Other.import, [template] { // CHECK:STDOUT: .C = %Other.C // CHECK:STDOUT: import Other//other_define // CHECK:STDOUT: } // CHECK:STDOUT: %Other.C: type = import_ref Other//other_define, C, loaded [template = constants.%C] // CHECK:STDOUT: %Other.import_ref.8f2: = import_ref Other//other_define, loc4_10, loaded [template = constants.%complete_type] // CHECK:STDOUT: %Other.import_ref.2c4 = import_ref Other//other_define, inst16 [no loc], unloaded // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Other = imports.%Other // CHECK:STDOUT: .c = %c // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Other.import = import Other // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %c.patt: %C = binding_pattern c // CHECK:STDOUT: %.loc6_1: %C = var_pattern %c.patt // CHECK:STDOUT: } // CHECK:STDOUT: %c.var: ref %C = var c // CHECK:STDOUT: %.loc6_13: type = splice_block %C.ref [template = constants.%C] { // CHECK:STDOUT: %Other.ref: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Other.C [template = constants.%C] // CHECK:STDOUT: } // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C [from "other_define.carbon"] { // CHECK:STDOUT: complete_type_witness = imports.%Other.import_ref.8f2 // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = imports.%Other.import_ref.2c4 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @__global_init() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %.loc6_19.1: %empty_struct_type = struct_literal () // CHECK:STDOUT: %.loc6_19.2: init %C = class_init (), file.%c.var [template = constants.%C.val] // CHECK:STDOUT: %.loc6_1: init %C = converted %.loc6_19.1, %.loc6_19.2 [template = constants.%C.val] // CHECK:STDOUT: assign file.%c.var, %.loc6_1 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- fail_extern.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other: = namespace file.%Other.import, [template] { // CHECK:STDOUT: .C = %Other.C // CHECK:STDOUT: import Other//other_extern // CHECK:STDOUT: } // CHECK:STDOUT: %Other.C: type = import_ref Other//other_extern, C, loaded [template = constants.%C] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Other = imports.%Other // CHECK:STDOUT: .c = %c // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Other.import = import Other // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %c.patt: = binding_pattern c // CHECK:STDOUT: %.loc14_1: = var_pattern %c.patt // CHECK:STDOUT: } // CHECK:STDOUT: %c.var: ref = var c // CHECK:STDOUT: %.loc14_13: type = splice_block %C.ref [template = constants.%C] { // CHECK:STDOUT: %Other.ref: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Other.C [template = constants.%C] // CHECK:STDOUT: } // CHECK:STDOUT: %c: = bind_name c, // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C [from "other_extern.carbon"]; // CHECK:STDOUT: // CHECK:STDOUT: fn @__global_init() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %.loc14: %empty_struct_type = struct_literal () // CHECK:STDOUT: assign file.%c.var, // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- fail_todo_merge_define_extern.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: %C.val: %C = struct_value () [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other: = namespace file.%Other.import, [template] { // CHECK:STDOUT: .C = %Other.C // CHECK:STDOUT: import Other//other_define // CHECK:STDOUT: import Other//other_extern // CHECK:STDOUT: } // CHECK:STDOUT: %Other.C: type = import_ref Other//other_define, C, loaded [template = constants.%C] // CHECK:STDOUT: %Other.import_ref.8f2: = import_ref Other//other_define, loc4_10, loaded [template = constants.%complete_type] // CHECK:STDOUT: %Other.import_ref.2c4 = import_ref Other//other_define, inst16 [no loc], unloaded // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Other = imports.%Other // CHECK:STDOUT: .c = %c // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Other.import = import Other // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %c.patt: %C = binding_pattern c // CHECK:STDOUT: %.loc19_1: %C = var_pattern %c.patt // CHECK:STDOUT: } // CHECK:STDOUT: %c.var: ref %C = var c // CHECK:STDOUT: %.loc19_13: type = splice_block %C.ref [template = constants.%C] { // CHECK:STDOUT: %Other.ref: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Other.C [template = constants.%C] // CHECK:STDOUT: } // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C [from "other_define.carbon"] { // CHECK:STDOUT: complete_type_witness = imports.%Other.import_ref.8f2 // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = imports.%Other.import_ref.2c4 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @__global_init() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %.loc19_19.1: %empty_struct_type = struct_literal () // CHECK:STDOUT: %.loc19_19.2: init %C = class_init (), file.%c.var [template = constants.%C.val] // CHECK:STDOUT: %.loc19_1: init %C = converted %.loc19_19.1, %.loc19_19.2 [template = constants.%C.val] // CHECK:STDOUT: assign file.%c.var, %.loc19_1 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: --- fail_conflict.carbon // CHECK:STDOUT: // CHECK:STDOUT: constants { // CHECK:STDOUT: %C: type = class_type @C [template] // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template] // CHECK:STDOUT: %complete_type: = complete_type_witness %empty_struct_type [template] // CHECK:STDOUT: %C.val: %C = struct_value () [template] // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: imports { // CHECK:STDOUT: %Core: = namespace file.%Core.import, [template] { // CHECK:STDOUT: import Core//prelude // CHECK:STDOUT: import Core//prelude/... // CHECK:STDOUT: } // CHECK:STDOUT: %Other: = namespace file.%Other.import, [template] { // CHECK:STDOUT: .C = %Other.C // CHECK:STDOUT: import Other//other_define // CHECK:STDOUT: import Other//other_conflict // CHECK:STDOUT: } // CHECK:STDOUT: %Other.C: type = import_ref Other//other_define, C, loaded [template = constants.%C] // CHECK:STDOUT: %Other.import_ref.8f2: = import_ref Other//other_define, loc4_10, loaded [template = constants.%complete_type] // CHECK:STDOUT: %Other.import_ref.2c4 = import_ref Other//other_define, inst16 [no loc], unloaded // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: file { // CHECK:STDOUT: package: = namespace [template] { // CHECK:STDOUT: .Core = imports.%Core // CHECK:STDOUT: .Other = imports.%Other // CHECK:STDOUT: .c = %c // CHECK:STDOUT: } // CHECK:STDOUT: %Core.import = import Core // CHECK:STDOUT: %Other.import = import Other // CHECK:STDOUT: name_binding_decl { // CHECK:STDOUT: %c.patt: %C = binding_pattern c // CHECK:STDOUT: %.loc19_1: %C = var_pattern %c.patt // CHECK:STDOUT: } // CHECK:STDOUT: %c.var: ref %C = var c // CHECK:STDOUT: %.loc19_13: type = splice_block %C.ref [template = constants.%C] { // CHECK:STDOUT: %Other.ref: = name_ref Other, imports.%Other [template = imports.%Other] // CHECK:STDOUT: %C.ref: type = name_ref C, imports.%Other.C [template = constants.%C] // CHECK:STDOUT: } // CHECK:STDOUT: %c: ref %C = bind_name c, %c.var // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: class @C [from "other_define.carbon"] { // CHECK:STDOUT: complete_type_witness = imports.%Other.import_ref.8f2 // CHECK:STDOUT: // CHECK:STDOUT: !members: // CHECK:STDOUT: .Self = imports.%Other.import_ref.2c4 // CHECK:STDOUT: } // CHECK:STDOUT: // CHECK:STDOUT: fn @__global_init() { // CHECK:STDOUT: !entry: // CHECK:STDOUT: %.loc19_19.1: %empty_struct_type = struct_literal () // CHECK:STDOUT: %.loc19_19.2: init %C = class_init (), file.%c.var [template = constants.%C.val] // CHECK:STDOUT: %.loc19_1: init %C = converted %.loc19_19.1, %.loc19_19.2 [template = constants.%C.val] // CHECK:STDOUT: assign file.%c.var, %.loc19_1 // CHECK:STDOUT: return // CHECK:STDOUT: } // CHECK:STDOUT: