mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 09:29:34 +00:00
Support for `fn` expressions with the same feature set as `fn` declarations. In particular, there is no support for captures, positional parameters, `=>` bodies, or `auto` return types. Note that this results in two parse nodes for each `=>` token. That's a bug, but it matches the behavior of function declarations, and will be fixed in a follow-up change. Assisted-by: Gemini via Antigravity
52 lines
1.7 KiB
Plaintext
52 lines
1.7 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/primitives.carbon
|
|
//
|
|
// AUTOUPDATE
|
|
// TIP: To test this file alone, run:
|
|
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/function/capture/uncaptured_locals.carbon
|
|
// TIP: To dump output, run:
|
|
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/function/capture/uncaptured_locals.carbon
|
|
|
|
// --- fail_todo_reference_uncaptured.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class X {}
|
|
|
|
fn Test() {
|
|
let x: X = {};
|
|
fn Inner() {
|
|
// TODO: This should fail. We can't reference `x` from here.
|
|
let unused y: X = x;
|
|
}
|
|
}
|
|
|
|
// Intentionally include an error here so we skip dominance checking, which CHECK-fails for the above example.
|
|
// CHECK:STDERR: fail_todo_reference_uncaptured.carbon:[[@LINE+4]]:14: error: name `error` not found [NameNotFound]
|
|
// CHECK:STDERR: fn Error() { error; }
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR:
|
|
fn Error() { error; }
|
|
|
|
// --- fail_todo_reference_uncaptured_lambda.carbon
|
|
library "[[@TEST_NAME]]";
|
|
|
|
class X {}
|
|
|
|
fn Test() {
|
|
let x: X = {};
|
|
(fn() {
|
|
// TODO: This should fail. We can't reference `x` from here.
|
|
let unused y: X = x;
|
|
});
|
|
}
|
|
|
|
// Intentionally include an error here so we skip dominance checking, which CHECK-fails for the above example.
|
|
// CHECK:STDERR: fail_todo_reference_uncaptured_lambda.carbon:[[@LINE+4]]:14: error: name `error` not found [NameNotFound]
|
|
// CHECK:STDERR: fn Error() { error; }
|
|
// CHECK:STDERR: ^~~~~
|
|
// CHECK:STDERR:
|
|
fn Error() { error; }
|