| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339 |
- // 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/packages/no_prelude/missing_prelude.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/packages/no_prelude/missing_prelude.carbon
- // --- fail_missing_prelude.carbon
- library "[[@TEST_NAME]]";
- // CHECK:STDERR: fail_missing_prelude.carbon:[[@LINE+4]]:8: error: package `Core` implicitly referenced here, but not found [CoreNotFound]
- // CHECK:STDERR: var n: i32;
- // CHECK:STDERR: ^~~
- // CHECK:STDERR:
- var n: i32;
- // --- prelude_empty.carbon
- package Core library "[[@TEST_NAME]]";
- // --- fail_missing_prelude_member.carbon
- library "[[@TEST_NAME]]";
- import Core library "prelude_empty";
- // CHECK:STDERR: fail_missing_prelude_member.carbon:[[@LINE+4]]:8: error: name `Core.Int32` implicitly referenced here, but not found [CoreNameNotFound]
- // CHECK:STDERR: var n: i32;
- // CHECK:STDERR: ^~~
- // CHECK:STDERR:
- var n: i32;
- // --- prelude_fake_int.carbon
- package Core library "[[@TEST_NAME]]";
- fn Int32() -> {} { return {}; }
- // --- use_fake_int.carbon
- library "[[@TEST_NAME]]";
- import Core library "prelude_fake_int";
- var n: {} = i32;
- // --- prelude_use_in_prelude.carbon
- package Core library "[[@TEST_NAME]]";
- // Core is not an imported package here.
- // Note that we are intentionally using a different type here from other cases
- // to test that this function is called, not the one from prelude_fake_int.
- fn Int32() -> () { return (); }
- var n: () = i32;
- // --- prelude_as_namespace.carbon
- library "[[@TEST_NAME]]";
- // TODO: Decide whether we want to accept this.
- namespace Core;
- fn Core.Int32() -> {} { return {}; }
- var n: {} = i32;
- // --- fail_prelude_as_class.carbon
- library "[[@TEST_NAME]]";
- // TODO: Decide whether we want to accept this.
- class Core {
- fn Int32() -> {} { return {}; }
- }
- // CHECK:STDERR: fail_prelude_as_class.carbon:[[@LINE+3]]:13: error: package `Core` implicitly referenced here, but not found [CoreNotFound]
- // CHECK:STDERR: var n: {} = i32;
- // CHECK:STDERR: ^~~
- var n: {} = i32;
- // CHECK:STDOUT: --- fail_missing_prelude.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %n.var: ref <error> = var n
- // CHECK:STDOUT: %n: ref <error> = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- prelude_empty.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_missing_prelude_member.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: import Core//prelude_empty
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %n.var: ref <error> = var n
- // CHECK:STDOUT: %n: ref <error> = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- prelude_fake_int.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %.1: type = struct_type {} [template]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %.2: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Int32 = %Int32.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Int32.decl: %Int32.type = fn_decl @Int32 [template = constants.%Int32] {
- // CHECK:STDOUT: %return.patt: %.1 = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %.1 = out_param_pattern %return.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %.loc4_16.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc4_16.2: type = converted %.loc4_16.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %return.param: ref %.1 = out_param runtime_param0
- // CHECK:STDOUT: %return: ref %.1 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> %.1 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %.loc4_28: %.1 = struct_literal ()
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template = constants.%struct]
- // CHECK:STDOUT: %.loc4_29: %.1 = converted %.loc4_28, %struct [template = constants.%struct]
- // CHECK:STDOUT: return %.loc4_29
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- use_fake_int.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %.1: type = struct_type {} [template]
- // CHECK:STDOUT: %.2: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: imports {
- // CHECK:STDOUT: %Core: <namespace> = namespace file.%Core.import, [template] {
- // CHECK:STDOUT: .Int32 = %import_ref
- // CHECK:STDOUT: import Core//prelude_fake_int
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %import_ref: %Int32.type = import_ref Core//prelude_fake_int, inst+8, loaded [template = constants.%Int32]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = imports.%Core
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.import = import Core
- // CHECK:STDOUT: %.loc6_9.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc6_9.2: type = converted %.loc6_9.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %n.var: ref %.1 = var n
- // CHECK:STDOUT: %n: ref %.1 = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> %.1;
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %Int32.call: init %.1 = call constants.%Int32()
- // CHECK:STDOUT: assign file.%n.var, %Int32.call
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- prelude_use_in_prelude.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %.1: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Int32 = %Int32.decl
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Int32.decl: %Int32.type = fn_decl @Int32 [template = constants.%Int32] {
- // CHECK:STDOUT: %return.patt: %.1 = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %.1 = out_param_pattern %return.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %.loc8_16.1: %.1 = tuple_literal ()
- // CHECK:STDOUT: %.loc8_16.2: type = converted %.loc8_16.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %return.param: ref %.1 = out_param runtime_param0
- // CHECK:STDOUT: %return: ref %.1 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %.loc10_9.1: %.1 = tuple_literal ()
- // CHECK:STDOUT: %.loc10_9.2: type = converted %.loc10_9.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %n.var: ref %.1 = var n
- // CHECK:STDOUT: %n: ref %.1 = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> %.1 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %.loc8_28: %.1 = tuple_literal ()
- // CHECK:STDOUT: %tuple: %.1 = tuple_value () [template = constants.%tuple]
- // CHECK:STDOUT: %.loc8_29: %.1 = converted %.loc8_28, %tuple [template = constants.%tuple]
- // CHECK:STDOUT: return %.loc8_29
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %Int32.call: init %.1 = call constants.%Int32()
- // CHECK:STDOUT: assign file.%n.var, %Int32.call
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- prelude_as_namespace.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %.1: type = struct_type {} [template]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %.2: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Int32 = %Int32.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Int32.decl: %Int32.type = fn_decl @Int32 [template = constants.%Int32] {
- // CHECK:STDOUT: %return.patt: %.1 = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %.1 = out_param_pattern %return.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %.loc7_21.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc7_21.2: type = converted %.loc7_21.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %return.param: ref %.1 = out_param runtime_param0
- // CHECK:STDOUT: %return: ref %.1 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %.loc9_9.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc9_9.2: type = converted %.loc9_9.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %n.var: ref %.1 = var n
- // CHECK:STDOUT: %n: ref %.1 = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> %.1 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %.loc7_33: %.1 = struct_literal ()
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template = constants.%struct]
- // CHECK:STDOUT: %.loc7_34: %.1 = converted %.loc7_33, %struct [template = constants.%struct]
- // CHECK:STDOUT: return %.loc7_34
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %Int32.call: init %.1 = call constants.%Int32()
- // CHECK:STDOUT: assign file.%n.var, %Int32.call
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_prelude_as_class.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %Core: type = class_type @Core [template]
- // CHECK:STDOUT: %.1: type = struct_type {} [template]
- // CHECK:STDOUT: %Int32.type: type = fn_type @Int32 [template]
- // CHECK:STDOUT: %.2: type = tuple_type () [template]
- // CHECK:STDOUT: %Int32: %Int32.type = struct_value () [template]
- // CHECK:STDOUT: %.3: <witness> = complete_type_witness %.1 [template]
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .Core = %Core.decl
- // CHECK:STDOUT: .n = %n
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %Core.decl: type = class_decl @Core [template = constants.%Core] {} {}
- // CHECK:STDOUT: %.loc12_9.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc12_9.2: type = converted %.loc12_9.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %n.var: ref %.1 = var n
- // CHECK:STDOUT: %n: ref %.1 = bind_name n, %n.var
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: class @Core {
- // CHECK:STDOUT: %Int32.decl: %Int32.type = fn_decl @Int32 [template = constants.%Int32] {
- // CHECK:STDOUT: %return.patt: %.1 = return_slot_pattern
- // CHECK:STDOUT: %return.param_patt: %.1 = out_param_pattern %return.patt, runtime_param0
- // CHECK:STDOUT: } {
- // CHECK:STDOUT: %.loc6_18.1: %.1 = struct_literal ()
- // CHECK:STDOUT: %.loc6_18.2: type = converted %.loc6_18.1, constants.%.1 [template = constants.%.1]
- // CHECK:STDOUT: %return.param: ref %.1 = out_param runtime_param0
- // CHECK:STDOUT: %return: ref %.1 = return_slot %return.param
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %.loc7: <witness> = complete_type_witness %.1 [template = constants.%.3]
- // CHECK:STDOUT:
- // CHECK:STDOUT: !members:
- // CHECK:STDOUT: .Self = constants.%Core
- // CHECK:STDOUT: .Int32 = %Int32.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @Int32() -> %.1 {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %.loc6_30: %.1 = struct_literal ()
- // CHECK:STDOUT: %struct: %.1 = struct_value () [template = constants.%struct]
- // CHECK:STDOUT: %.loc6_31: %.1 = converted %.loc6_30, %struct [template = constants.%struct]
- // CHECK:STDOUT: return %.loc6_31
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @__global_init() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: assign file.%n.var, <error>
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|