summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/interactive.cc9
-rw-r--r--src/op.cc15
2 files changed, 19 insertions, 5 deletions
diff --git a/src/interactive.cc b/src/interactive.cc
index 54c7fd6c..b95057dd 100644
--- a/src/interactive.cc
+++ b/src/interactive.cc
@@ -169,15 +169,14 @@ void interactive_t::verify_arguments() const
DEBUG("interactive.verify", "Remaining args are optional");
if (wrong_arg) {
- throw_(std::logic_error,
- _("Expected %1 for argument %2, but received %3")
- << label << offset << vlabel);
+ throw_(calc_error, _("Expected %1 for argument %2, but received %3")
+ << label << offset << vlabel);
}
else if (*p && ! optional && ! next_arg) {
- throw_(std::logic_error, _("Too few arguments to function"));
+ throw_(calc_error, _("Too few arguments to function"));
}
else if (! *p && next_arg) {
- throw_(std::logic_error, _("Too many arguments to function"));
+ throw_(calc_error, _("Too many arguments to function"));
}
}
diff --git a/src/op.cc b/src/op.cc
index 8f73493d..0feb157f 100644
--- a/src/op.cc
+++ b/src/op.cc
@@ -68,6 +68,17 @@ namespace {
}
return seq;
}
+
+ void check_type_context(scope_t& scope, value_t& result)
+ {
+ if (scope.type_context() != value_t::VOID &&
+ result.type() != scope.type_context()) {
+ throw_(calc_error,
+ _("Expected return of %1, but received %2")
+ << result.label(scope.type_context())
+ << result.label());
+ }
+ }
}
expr_t::ptr_op_t expr_t::op_t::compile(scope_t& scope, const int depth)
@@ -154,6 +165,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
call_scope_t call_args(scope, scope.type_context());
result = left()->compile(call_args, depth + 1)
->calc(call_args, locus, depth + 1);
+ check_type_context(scope, result);
break;
}
@@ -163,6 +175,7 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
// resolved.
call_scope_t call_args(scope, scope.type_context());
result = as_function()(call_args);
+ check_type_context(scope, result);
#if defined(DEBUG_ON)
skip_debug = true;
#endif
@@ -256,6 +269,8 @@ value_t expr_t::op_t::calc(scope_t& scope, ptr_op_t * locus, const int depth)
result = func->as_function()(call_args);
else
result = func->calc(call_args, locus, depth + 1);
+
+ check_type_context(scope, result);
break;
}