summaryrefslogtreecommitdiff
path: root/src/main/java/org/zwobble
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2026-12-04 11:02:13 +0000
committerMichael Williamson <mike@zwobble.org>2026-12-04 11:02:13 +0000
commit6af47e172db351c227349d9cc803afc8923c797b (patch)
tree4e77c2fad99191093abe5230a4b96c9fa334869b /src/main/java/org/zwobble
parent27547fc1493ad52f26cdd6c8ad84c86dc62e4bfa (diff)
Check that receiver is callable
Diffstat (limited to 'src/main/java/org/zwobble')
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java4
-rw-r--r--src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NotCallableError.java18
2 files changed, 21 insertions, 1 deletions
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
index a796d16..b92fe13 100644
--- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java
@@ -807,7 +807,9 @@ public class TypeChecker {
var receiver = typeCheckExpression(untyped.receiver(), Optional.empty(), context);
- var receiverType = (FunctionType) receiver.type();
+ if (!(receiver.type() instanceof FunctionType receiverType)) {
+ throw new NotCallableError(receiver.type(), untyped.receiver().source());
+ }
if (receiverType.params().size() != untyped.args().size()) {
throw new WrongNumberOfArgsError(
diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NotCallableError.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NotCallableError.java
new file mode 100644
index 0000000..90143fb
--- /dev/null
+++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/NotCallableError.java
@@ -0,0 +1,18 @@
+package org.zwobble.hobgoblin.compiler.typechecker.errors;
+
+import org.zwobble.hobgoblin.compiler.errors.SourceError;
+import org.zwobble.hobgoblin.compiler.sources.Source;
+import org.zwobble.hobgoblin.compiler.types.Type;
+
+public class NotCallableError extends SourceError {
+ private final Type type;
+
+ public NotCallableError(Type type, Source source) {
+ super(type.describe() + " is not callable", source);
+ this.type = type;
+ }
+
+ public Type type() {
+ return type;
+ }
+}