mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-09-28 16:14:53 +01:00
Factor out AST node for function return types. (#912)
This enables us to stop treating the return type as a Pattern (which is really isn't), treat return types more consistently with other static types in the typechecker, and drop ReturnTypeContext. Additional changes: - Merge TypeCheckFunDef with TypeOfFunDef. - Handle implicit conversions in `return` statements. - Require function type literals to have an explicit `->`. - Move consistency check for omitted returns from TypeChecker to ResolveControlFlow.
This commit is contained in:
+1
-3
@@ -7,15 +7,13 @@
|
||||
// RUN: not executable_semantics --trace %s 2>&1 | \
|
||||
// RUN: FileCheck --match-full-lines --allow-unused-prefixes %s
|
||||
// AUTOUPDATE: executable_semantics %s
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/function/auto_return/fail_separate_decl.carbon:15: syntax error, unexpected SEMICOLON, expecting LEFT_CURLY_BRACE
|
||||
// CHECK: COMPILATION ERROR: {{.*}}/executable_semantics/testdata/function/auto_return/fail_separate_decl.carbon:15: Function declaration has deduced return type but no body
|
||||
|
||||
package ExecutableSemanticsTest api;
|
||||
|
||||
// This declaration is not allowed.
|
||||
fn Add(x: i32, y: i32) -> auto;
|
||||
|
||||
fn Add(x: i32, y: i32) -> auto { return x + y; }
|
||||
|
||||
fn Main() -> i32 {
|
||||
return Add(1, 2) - 3;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user