From 5ab307fa798626d7f852ebec65f87e2af7487c53 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 29 Oct 2023 18:23:36 +0000 Subject: Infer return type of function expressions properly --- .../org/shedlang/compiler/typechecker/TypeChecker.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'src/main/java/org') diff --git a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java index 15623e98..17cf42a3 100644 --- a/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/shedlang/compiler/typechecker/TypeChecker.java @@ -627,13 +627,6 @@ public class TypeChecker { ) { var typedSignature = typeCheckFunctionSignature(untyped.signature(), context); - var type = new FunctionType( - functionSignatureToPositionalParams(typedSignature), - functionSignatureToNamedParams(typedSignature), - functionSignatureToEffect(typedSignature), - functionSignatureToReturnType(typedSignature).orElse(Types.UNIT) - ); - var typedBodyResult = typeCheckFunctionBody( untyped.body(), typedSignature, @@ -642,6 +635,13 @@ public class TypeChecker { var typedBody = typedBodyResult.value(); context = typedBodyResult.context(); + var type = new FunctionType( + functionSignatureToPositionalParams(typedSignature), + functionSignatureToNamedParams(typedSignature), + functionSignatureToEffect(typedSignature), + typedBody.type() + ); + var typed = new TypedFunctionExpressionNode( typedSignature, typedBody, -- cgit v1.2.3