diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-12-04 10:55:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-12-04 10:55:59 +0000 |
| commit | 78d8871875d0d9e1c6375e283b01cf9583d21f73 (patch) | |
| tree | 157e8c8c7ab6285d76b71e1d18bc18438227f636 /src | |
| parent | 6eebe3630f767458597c8f375f01e59a92a2855e (diff) | |
Add test for calling function with no args
Diffstat (limited to 'src')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java | 4 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java | 40 |
2 files changed, 44 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java b/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java index 357fa64..6b7b8ac 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/types/Types.java @@ -43,4 +43,8 @@ public class Types { public static Type constantNumber(BigDecimal value) { return new TypeLevelValueType(new ConstantNumber(value)); } + + public static Type function(List<Type> params, Type returns) { + return new FunctionType(params, returns); + } } diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java new file mode 100644 index 0000000..2f14c75 --- /dev/null +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java @@ -0,0 +1,40 @@ +package org.zwobble.hobgoblin.compiler.typechecker; + +import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedCallNode; +import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedReferenceNode; +import org.zwobble.hobgoblin.compiler.builtins.NativeTypes; +import org.zwobble.hobgoblin.compiler.sources.NullSource; +import org.zwobble.hobgoblin.compiler.types.NamespaceName; +import org.zwobble.hobgoblin.compiler.types.Types; + +import java.util.List; +import java.util.Optional; + +import static org.zwobble.hobgoblin.compiler.ast.typed.TypedCallNodeMatcher.isTypedCallNode; +import static org.zwobble.hobgoblin.compiler.ast.typed.TypedReferenceNodeMatcher.isTypedReferenceNode; +import static org.zwobble.precisely.AssertThat.assertThat; +import static org.zwobble.precisely.Matchers.equalTo; +import static org.zwobble.precisely.Matchers.isSequence; + +public class TypeCheckerCallTests { + @Test + public void canCallFunctionWithNoArgs() { + var untyped = UntypedCallNode.arbitrary() + .withReceiver(UntypedReferenceNode.arbitrary().withName("f")) + .withArgs(List.of()) + .build(); + var globalContext = TypeCheckerContextArb.globalContext(); + var namespaceName = NamespaceName.of("App"); + var namespaceContext = globalContext.enterNamespace(namespaceName) + .define("f", Types.function(List.of(), NativeTypes.STRING), NullSource.INSTANCE) + .endDeclarations(); + + var typed = TypeChecker.typeCheckExpression(untyped, Optional.empty(), namespaceContext); + + assertThat(typed, isTypedCallNode() + .withReceiver(isTypedReferenceNode().withName(equalTo("f"))) + .withArgs(isSequence()) + ); + } +} |
