From c7d528851c816f59740b83fa93d99ee857695d59 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Wed, 7 Jun 2023 20:07:20 +0100 Subject: Parse effect in function definition --- .../compiler/ast/UntypedFunctionDefinitionNodeMatcher.java | 2 +- .../compiler/parser/ParserFunctionDefinitionTests.java | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/ast/UntypedFunctionDefinitionNodeMatcher.java b/src/test/java/org/shedlang/compiler/ast/UntypedFunctionDefinitionNodeMatcher.java index 775cf5f5..0a52482d 100644 --- a/src/test/java/org/shedlang/compiler/ast/UntypedFunctionDefinitionNodeMatcher.java +++ b/src/test/java/org/shedlang/compiler/ast/UntypedFunctionDefinitionNodeMatcher.java @@ -32,7 +32,7 @@ public class UntypedFunctionDefinitionNodeMatcher extends MatcherBuilder x.body(), body)); } - public UntypedFunctionDefinitionNodeMatcher withEffect(Matcher> effect) { + public UntypedFunctionDefinitionNodeMatcher withEffect(Matcher> effect) { return with(has("effect", x -> x.effect(), effect)); } diff --git a/src/test/java/org/shedlang/compiler/parser/ParserFunctionDefinitionTests.java b/src/test/java/org/shedlang/compiler/parser/ParserFunctionDefinitionTests.java index 34c50065..80ecb5b2 100644 --- a/src/test/java/org/shedlang/compiler/parser/ParserFunctionDefinitionTests.java +++ b/src/test/java/org/shedlang/compiler/parser/ParserFunctionDefinitionTests.java @@ -26,4 +26,18 @@ public class ParserFunctionDefinitionTests { .withBody(isSequence()) ); } + @Test + public void canParseFunctionWithEffect() { + var source = """ + fun f() ! Io -> Unit { + }"""; + + var node = parseString(source, Parser::parseNamespaceStatement); + + assertThat( + node, + isUntypedFunctionDefinitionNode() + .withEffect(isOptionalOf(isUntypedTypeLevelReferenceNode("Io"))) + ); + } } -- cgit v1.2.3