diff options
author | John Wiegley <johnw@newartisans.com> | 2010-06-12 22:25:10 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2010-06-13 01:03:49 -0400 |
commit | dcdd9c4a5630db5eaf9fe20ad391c60dc7209960 (patch) | |
tree | c6cd188c815a33662cfa2099f483049d144a96ad /src/op.cc | |
parent | 1bc5b894dfd9412a60c4db16e9a4e49ddddad5fd (diff) | |
download | fork-ledger-dcdd9c4a5630db5eaf9fe20ad391c60dc7209960.tar.gz fork-ledger-dcdd9c4a5630db5eaf9fe20ad391c60dc7209960.tar.bz2 fork-ledger-dcdd9c4a5630db5eaf9fe20ad391c60dc7209960.zip |
If a type context exists, confirm the result matches
Diffstat (limited to 'src/op.cc')
-rw-r--r-- | src/op.cc | 15 |
1 files changed, 15 insertions, 0 deletions
@@ -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; } |