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:
Geoff Romer
2021-11-12 11:30:31 -08:00
committed by GitHub
parent a4aff26821
commit d854fb93cb
11 changed files with 255 additions and 229 deletions
@@ -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;
}