From 2aa8d37fe9468ba23732869187e7c6e45bc72d62 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 29 Oct 2023 21:19:30 +0000 Subject: Pass partial signature when type checking function body --- .../typechecker/TypeCheckerFunctionBodyTests.java | 86 +++++++++++----------- 1 file changed, 42 insertions(+), 44 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java index dbd860e7..37c5d6dd 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionBodyTests.java @@ -1,8 +1,6 @@ package org.shedlang.compiler.typechecker; import org.junit.jupiter.api.Test; -import org.shedlang.compiler.ast.typed.Typed; -import org.shedlang.compiler.ast.typed.TypedFunctionSignatureNode; import org.shedlang.compiler.ast.untyped.Untyped; import org.shedlang.compiler.ast.untyped.UntypedCallNode; import org.shedlang.compiler.typechecker.errors.DuplicateVariableNameError; @@ -26,8 +24,8 @@ public class TypeCheckerFunctionBodyTests { @Test public void canTypeCheckEmptyBody() { var untyped = Untyped.block(List.of()); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -42,10 +40,10 @@ public class TypeCheckerFunctionBodyTests { @Test public void paramsMustHaveUniqueNames() { var untyped = Untyped.block(List.of()); - var signature = TypedFunctionSignatureNode.builder() - .addPositionalParam("x", Typed.typeLevelReference("String", Types.STRING)) - .addPositionalParam("x", Typed.typeLevelReference("Int", Types.INT)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .addPositionalParam("x", Types.STRING) + .addPositionalParam("x", Types.INT) + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -62,8 +60,8 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.stringLiteral("hello")) )); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -83,9 +81,9 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.reference("x")) )); - var signature = TypedFunctionSignatureNode.builder() - .addPositionalParam("x", Typed.typeLevelReference("String", Types.STRING)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .addPositionalParam("x", Types.STRING) + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -105,9 +103,9 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.reference("x")) )); - var signature = TypedFunctionSignatureNode.builder() - .addNamedParam("x", Typed.typeLevelReference("String", Types.STRING)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .addNamedParam("x", Types.STRING) + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -132,9 +130,9 @@ public class TypeCheckerFunctionBodyTests { .build() ) )); - var signature = TypedFunctionSignatureNode.builder() - .withEffect(Typed.typeLevelReference("Io", Effects.IO)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withEffect(Effects.IO) + .withReturnType(Types.UNIT) .build(); var functionType = FunctionType.builder() .withEffect(Effects.IO) @@ -161,8 +159,8 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.functionReturn(Untyped.intLiteral(42)) )); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("String", Types.STRING)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.STRING) .build(); var context = TypeCheckerContext.EMPTY; @@ -178,8 +176,8 @@ public class TypeCheckerFunctionBodyTests { @Test public void givenReturnTypeIsUnitWhenBodyHasNoReturnThenFunctionTypeChecks() { var untyped = Untyped.block(List.of()); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -189,8 +187,8 @@ public class TypeCheckerFunctionBodyTests { @Test public void givenReturnTypeIsNotUnitWhenBodyHasNoReturnThenFunctionFailsTypeCheck() { var untyped = Untyped.block(List.of()); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("String", Types.STRING)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.STRING) .build(); var context = TypeCheckerContext.EMPTY; @@ -208,8 +206,8 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.blockReturn(Untyped.stringLiteral("hello")) )); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("String", Types.STRING)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.STRING) .build(); var context = TypeCheckerContext.EMPTY; @@ -221,7 +219,7 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.stringLiteral("")) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY; @@ -250,7 +248,7 @@ public class TypeCheckerFunctionBodyTests { Untyped.block(List.of()) )) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY @@ -272,7 +270,7 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.functionReturn(Untyped.stringLiteral("")) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY; @@ -303,7 +301,7 @@ public class TypeCheckerFunctionBodyTests { )) )) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY @@ -325,7 +323,7 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.blockReturn(Untyped.stringLiteral("")) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY; @@ -355,7 +353,7 @@ public class TypeCheckerFunctionBodyTests { )), Untyped.blockReturn(Untyped.intLiteral(0)) )); - var signature = TypedFunctionSignatureNode.builder() + var signature = PartialFunctionSignature.builder() .withoutReturnType() .build(); var context = TypeCheckerContext.EMPTY @@ -377,8 +375,8 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.reference("y")) )); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY .enterGlobal(P.map( @@ -402,9 +400,9 @@ public class TypeCheckerFunctionBodyTests { var untyped = Untyped.block(List.of( Untyped.expressionStatement(Untyped.reference("x")) )); - var signature = TypedFunctionSignatureNode.builder() - .addPositionalParam("x", Typed.typeLevelReference("String", Types.STRING)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .addPositionalParam("x", Types.STRING) + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY; @@ -432,8 +430,8 @@ public class TypeCheckerFunctionBodyTests { )) )) )); - var signature = TypedFunctionSignatureNode.builder() - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY .enterGlobal(P.map( @@ -468,10 +466,10 @@ public class TypeCheckerFunctionBodyTests { Untyped.block(List.of()) )) )); - var signature = TypedFunctionSignatureNode.builder() - .addPositionalParam("argPositional", Typed.typeLevelReference("Unit", Types.UNIT)) - .addNamedParam("argNamed", Typed.typeLevelReference("Unit", Types.UNIT)) - .withReturnType(Typed.typeLevelReference("Unit", Types.UNIT)) + var signature = PartialFunctionSignature.builder() + .addPositionalParam("argPositional", Types.UNIT) + .addNamedParam("argNamed", Types.UNIT) + .withReturnType(Types.UNIT) .build(); var context = TypeCheckerContext.EMPTY .enterGlobal(P.map( -- cgit v1.2.3