aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
index 5bc73325..5e80c9a0 100644
--- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
+++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java
@@ -268,6 +268,25 @@ public class TypeCheckerFunctionBodyTests {
}
@Test
+ public void givenNoExplicitReturnTypeWhenThereIsOneExplicitReturnThenReturnTypeIsTypeOfReturnExpression() {
+ var untyped = Untyped.block(List.of(
+ Untyped.functionReturn(Untyped.stringLiteral(""))
+ ));
+ var signature = TypedFunctionSignatureNode.builder()
+ .withoutReturnType()
+ .build();
+ var context = TypeCheckerContext.EMPTY;
+
+ var typed = typeCheckFunctionBody(untyped, signature, context);
+
+ assertThat(
+ typed.value(),
+ isTypedFunctionBodyNode()
+ .withType(Types.STRING)
+ );
+ }
+
+ @Test
public void freeVariablesIncludeVariablesReferencedInFunctionButDefinedOutsideOfFunction() {
var untyped = Untyped.block(List.of(
Untyped.expressionStatement(Untyped.reference("y"))