| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123 |
- // 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/function/definition/no_prelude/fail_local_decl.carbon
- // TIP: To dump output, run:
- // TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/definition/no_prelude/fail_local_decl.carbon
- // --- fail_virtual.carbon
- library "[[@TEST_NAME]]";
- fn F() {
- // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `default` not allowed; requires interface scope [ModifierRequiresInterface]
- // CHECK:STDERR: default fn F();
- // CHECK:STDERR: ^~~~~~~
- // CHECK:STDERR:
- default fn F();
- // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `impl` not allowed; requires class scope [ModifierRequiresClass]
- // CHECK:STDERR: impl fn G();
- // CHECK:STDERR: ^~~~
- // CHECK:STDERR:
- impl fn G();
- // CHECK:STDERR: fail_virtual.carbon:[[@LINE+4]]:3: error: `virtual` not allowed; requires class scope [ModifierRequiresClass]
- // CHECK:STDERR: virtual fn H();
- // CHECK:STDERR: ^~~~~~~
- // CHECK:STDERR:
- virtual fn H();
- }
- // --- fail_access.carbon
- library "[[@TEST_NAME]]";
- fn F() {
- // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `private` not allowed; requires class or file scope [ModifierPrivateNotAllowed]
- // CHECK:STDERR: private var v: {};
- // CHECK:STDERR: ^~~~~~~
- // CHECK:STDERR:
- private var v: {};
- // CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
- // CHECK:STDERR: protected var w: {};
- // CHECK:STDERR: ^~~~~~~~~
- // CHECK:STDERR:
- protected var w: {};
- }
- // CHECK:STDOUT: --- fail_virtual.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %F.type.b25: type = fn_type @F.1 [template]
- // CHECK:STDOUT: %F.c41: %F.type.b25 = struct_value () [template]
- // CHECK:STDOUT: %F.type.21a: type = fn_type @F.2 [template]
- // CHECK:STDOUT: %F.c14: %F.type.21a = struct_value () [template]
- // CHECK:STDOUT: %G.type: type = fn_type @G [template]
- // CHECK:STDOUT: %G: %G.type = struct_value () [template]
- // CHECK:STDOUT: %H.type: type = fn_type @H [template]
- // CHECK:STDOUT: %H: %H.type = struct_value () [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .F = %F.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %F.decl: %F.type.b25 = fn_decl @F.1 [template = constants.%F.c41] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @F.1() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: %F.decl: %F.type.21a = fn_decl @F.2 [template = constants.%F.c14] {} {}
- // CHECK:STDOUT: %G.decl: %G.type = fn_decl @G [template = constants.%G] {} {}
- // CHECK:STDOUT: %H.decl: %H.type = fn_decl @H [template = constants.%H] {} {}
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @F.2();
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @G();
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @H();
- // CHECK:STDOUT:
- // CHECK:STDOUT: --- fail_access.carbon
- // CHECK:STDOUT:
- // CHECK:STDOUT: constants {
- // CHECK:STDOUT: %F.type: type = fn_type @F [template]
- // CHECK:STDOUT: %F: %F.type = struct_value () [template]
- // CHECK:STDOUT: %empty_struct_type: type = struct_type {} [template]
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: file {
- // CHECK:STDOUT: package: <namespace> = namespace [template] {
- // CHECK:STDOUT: .F = %F.decl
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %F.decl: %F.type = fn_decl @F [template = constants.%F] {} {}
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
- // CHECK:STDOUT: fn @F() {
- // CHECK:STDOUT: !entry:
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %v.patt: %empty_struct_type = binding_pattern v
- // CHECK:STDOUT: %.loc9_11: %empty_struct_type = var_pattern %v.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %v.var: ref %empty_struct_type = var v
- // CHECK:STDOUT: %.loc9_19.1: type = splice_block %.loc9_19.3 [template = constants.%empty_struct_type] {
- // CHECK:STDOUT: %.loc9_19.2: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT: %.loc9_19.3: type = converted %.loc9_19.2, constants.%empty_struct_type [template = constants.%empty_struct_type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %v: ref %empty_struct_type = bind_name v, %v.var
- // CHECK:STDOUT: name_binding_decl {
- // CHECK:STDOUT: %w.patt: %empty_struct_type = binding_pattern w
- // CHECK:STDOUT: %.loc14_13: %empty_struct_type = var_pattern %w.patt
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %w.var: ref %empty_struct_type = var w
- // CHECK:STDOUT: %.loc14_21.1: type = splice_block %.loc14_21.3 [template = constants.%empty_struct_type] {
- // CHECK:STDOUT: %.loc14_21.2: %empty_struct_type = struct_literal ()
- // CHECK:STDOUT: %.loc14_21.3: type = converted %.loc14_21.2, constants.%empty_struct_type [template = constants.%empty_struct_type]
- // CHECK:STDOUT: }
- // CHECK:STDOUT: %w: ref %empty_struct_type = bind_name w, %w.var
- // CHECK:STDOUT: return
- // CHECK:STDOUT: }
- // CHECK:STDOUT:
|