From 5944d9423280e78c23252c2c8468e117efe0ed55 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 13 Jun 2023 20:49:11 +0100 Subject: Store type of function on node --- .../compiler/ast/typed/TypedFunctionDefinitionNodeMatcher.java | 5 +++++ .../compiler/typechecker/TypeCheckerFunctionDefinitionTests.java | 9 +++++++++ 2 files changed, 14 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/typed/TypedFunctionDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/typed/TypedFunctionDefinitionNodeMatcher.java index b1c6e59a..c1d047af 100644 --- a/src/test/java/org/shedlang/compiler/ast/typed/TypedFunctionDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/typed/TypedFunctionDefinitionNodeMatcher.java @@ -3,6 +3,7 @@ package org.shedlang.compiler.ast.typed; import org.pcollections.Empty; import org.pcollections.PVector; import org.shedlang.compiler.testing.MatcherBuilder; +import org.shedlang.compiler.types.FunctionType; import org.zwobble.precisely.Matcher; import java.util.Optional; @@ -52,4 +53,8 @@ public class TypedFunctionDefinitionNodeMatcher extends MatcherBuilder> returnType) { return with(has("returnType", x -> x.returnType(), returnType)); } + + public TypedFunctionDefinitionNodeMatcher withType(FunctionType type) { + return with(has("type", x -> x.type(), equalTo(type))); + } } diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java index 3eb177cc..f3cbf0fe 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerFunctionDefinitionTests.java @@ -4,9 +4,12 @@ import org.junit.jupiter.api.Test; import org.shedlang.compiler.ast.untyped.Untyped; import org.shedlang.compiler.ast.untyped.UntypedFunctionDefinitionNode; import org.shedlang.compiler.types.Effects; +import org.shedlang.compiler.types.FunctionType; +import org.shedlang.compiler.types.NamedParam; import org.shedlang.compiler.types.Types; import org.shedlang.compiler.util.P; +import java.util.List; import java.util.Map; import static org.shedlang.compiler.ast.typed.TypedNodeMatchers.*; @@ -33,6 +36,7 @@ public class TypeCheckerFunctionDefinitionTests { .withEffect(isOptionalEmpty()) .withReturnType(isTypedTypeLevelReferenceNode("Unit", Types.UNIT)) .withBody(isSequence()) + .withType(new FunctionType(List.of(), List.of(), Types.UNIT)) ); } @@ -61,6 +65,11 @@ public class TypeCheckerFunctionDefinitionTests { isSequence(isTypedParamNode("y", isTypedTypeLevelReferenceNode("Int", Types.INT))) ) ) + .withType(new FunctionType( + List.of(Types.STRING), + List.of(new NamedParam("y", Types.INT)), + Types.UNIT + )) ); } @Test -- cgit v1.2.3