mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-24 19:32:38 +00:00
Initial support for fn expressions. (#7893)
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
This commit is contained in:
1 parent
66bf1415ac
commit
1b0a5709e6
24 files changed
+2015
-308
No files matched your search
@@ -0,0 +1,51 @@
|
||||
// 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; }
|
||||
Reference in new issue
Block a user