diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-12-04 10:59:07 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-12-04 10:59:07 +0000 |
| commit | 27547fc1493ad52f26cdd6c8ad84c86dc62e4bfa (patch) | |
| tree | d1628cc9eb9bf68d827bf617be55da01cb477ec8 /src/main | |
| parent | 78d8871875d0d9e1c6375e283b01cf9583d21f73 (diff) | |
Check number of args for call
Diffstat (limited to 'src/main')
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java | 8 | ||||
| -rw-r--r-- | src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/WrongNumberOfArgsError.java | 23 |
2 files changed, 31 insertions, 0 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 96328a8..a796d16 100644 --- a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java +++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/TypeChecker.java @@ -809,6 +809,14 @@ public class TypeChecker { var receiverType = (FunctionType) receiver.type(); + if (receiverType.params().size() != untyped.args().size()) { + throw new WrongNumberOfArgsError( + receiverType.params().size(), + untyped.args().size(), + untyped.source() + ); + } + var args = untyped.args().stream() .map(untypedArg -> typeCheckExpression(untypedArg, Optional.empty(), context)) .toList(); diff --git a/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/WrongNumberOfArgsError.java b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/WrongNumberOfArgsError.java new file mode 100644 index 0000000..9466d1d --- /dev/null +++ b/src/main/java/org/zwobble/hobgoblin/compiler/typechecker/errors/WrongNumberOfArgsError.java @@ -0,0 +1,23 @@ +package org.zwobble.hobgoblin.compiler.typechecker.errors; + +import org.zwobble.hobgoblin.compiler.errors.SourceError; +import org.zwobble.hobgoblin.compiler.sources.Source; + +public class WrongNumberOfArgsError extends SourceError { + private final int expectedArgCount; + private final int actualArgCount; + + public WrongNumberOfArgsError(int expectedArgCount, int actualArgCount, Source source) { + super("expected " + expectedArgCount + " args, but got " + actualArgCount, source); + this.expectedArgCount = expectedArgCount; + this.actualArgCount = actualArgCount; + } + + public int expectedArgCount() { + return expectedArgCount; + } + + public int actualArgCount() { + return actualArgCount; + } +} |
