mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 08:10:10 +01:00
When a `var` is not explicitly given an initializer, initialize it in one of two ways: * If its type implements the new interface `Core.Default`, call `Core.Default.Op` to initialize it. * Otherwise, if its type implements `UnformedInit`, leave it in an unformed state. For now, this is always an uninitialized state, but that will change in the future. * If neither of those apply, the `var` declaration is ill-formed. This is a step towards implementing leads decision #6739 and proposals #257 and #5913. Assisted-by: Gemini 3.1 Pro via Antigravity --------- Co-authored-by: Geoff Romer <gromer@google.com>
51 lines
2.0 KiB
Plaintext
51 lines
2.0 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/destroy.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/definition/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/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: `override` not allowed; requires class scope [ModifierRequiresClass]
|
|
// CHECK:STDERR: override fn G();
|
|
// CHECK:STDERR: ^~~~~~~~
|
|
// CHECK:STDERR:
|
|
override 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 unused v: {} = {};
|
|
// CHECK:STDERR: ^~~~~~~
|
|
// CHECK:STDERR:
|
|
private var unused v: {} = {};
|
|
// CHECK:STDERR: fail_access.carbon:[[@LINE+4]]:3: error: `protected` not allowed; requires class scope [ModifierProtectedNotAllowed]
|
|
// CHECK:STDERR: protected var unused w: {} = {};
|
|
// CHECK:STDERR: ^~~~~~~~~
|
|
// CHECK:STDERR:
|
|
protected var unused w: {} = {};
|
|
}
|