aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-28 20:03:27 +0100
committergingerBill <bill@gingerbill.org>2018-08-28 20:03:27 +0100
commitae2af8315ee8538774efe2cf608d4be50be5305a (patch)
treed810da5415b8af9808d40153b9499b6e91dc90fd /src/check_type.cpp
parentadbb3bb75fc161988fb6e4fdf07260601a846aaa (diff)
Allow for default parameters that are non-constant entities, but not any non-constant expression
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 5997a110a..f3ebf50a0 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -1038,7 +1038,8 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type *
param_value.value = exact_value_procedure(expr);
} else {
Entity *e = nullptr;
- if (o.mode == Addressing_Value && is_type_proc(o.type)) {
+ // if (o.mode == Addressing_Value && is_type_proc(o.type)) {
+ if (o.mode == Addressing_Value || o.mode == Addressing_Variable) {
Operand x = {};
if (expr->kind == Ast_Ident) {
e = check_ident(ctx, &x, expr, nullptr, nullptr, false);
@@ -1047,12 +1048,21 @@ ParameterValue handle_parameter_value(CheckerContext *ctx, Type *in_type, Type *
}
}
- if (e != nullptr && e->kind == Entity_Procedure) {
- param_value.kind = ParameterValue_Constant;
- param_value.value = exact_value_procedure(e->identifier);
- add_entity_use(ctx, e->identifier, e);
+ if (e != nullptr) {
+ if (e->kind == Entity_Procedure) {
+ param_value.kind = ParameterValue_Constant;
+ param_value.value = exact_value_procedure(e->identifier);
+ add_entity_use(ctx, e->identifier, e);
+ } else {
+ param_value.kind = ParameterValue_Value;
+ param_value.ast_value = expr;
+ add_entity_use(ctx, e->identifier, e);
+ }
+ } else if (allow_caller_location && o.mode == Addressing_Context) {
+ param_value.kind = ParameterValue_Value;
+ param_value.ast_value = expr;
} else {
- error(expr, "Default parameter must be a constant %d", o.mode);
+ error(expr, "Default parameter must be a constant");
}
}
} else {