diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-12-04 11:02:13 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-12-04 11:02:13 +0000 |
| commit | 6af47e172db351c227349d9cc803afc8923c797b (patch) | |
| tree | 4e77c2fad99191093abe5230a4b96c9fa334869b /src/test/java/org/zwobble | |
| parent | 27547fc1493ad52f26cdd6c8ad84c86dc62e4bfa (diff) | |
Check that receiver is callable
Diffstat (limited to 'src/test/java/org/zwobble')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java index 51ecf09..4d8400b 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerCallTests.java @@ -6,6 +6,7 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNumberLiteralNode; 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.typechecker.errors.NotCallableError; import org.zwobble.hobgoblin.compiler.typechecker.errors.WrongNumberOfArgsError; import org.zwobble.hobgoblin.compiler.types.NamespaceName; import org.zwobble.hobgoblin.compiler.types.Types; @@ -42,6 +43,26 @@ public class TypeCheckerCallTests { } @Test + public void whenReceiverIsNotCallableThenErrorIsThrown() { + 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", NativeTypes.STRING, NullSource.INSTANCE) + .endDeclarations(); + + var error = assertThrows( + NotCallableError.class, + () -> TypeChecker.typeCheckExpression(untyped, Optional.empty(), namespaceContext) + ); + + assertThat(error.type(), equalTo(NativeTypes.STRING)); + } + + @Test public void whenCallIsMissingArgsThenErrorIsThrown() { var untyped = UntypedCallNode.arbitrary() .withReceiver(UntypedReferenceNode.arbitrary().withName("f")) |
