Fixes bug 608187.
write_string ("class ");
}
- if (is_weak (f.variable_type)) {
+ if (f.variable_type.is_weak ()) {
write_string ("weak ");
}
} else if (param.direction == ParameterDirection.OUT) {
write_string ("out ");
}
- if (is_weak (param.variable_type)) {
+ if (param.variable_type.is_weak ()) {
write_string ("unowned ");
}
}
}
private void write_return_type (DataType type) {
- if (is_weak (type)) {
+ if (type.is_weak ()) {
write_string ("unowned ");
}
write_type (type);
}
- private bool is_weak (DataType type) {
- if (type.value_owned) {
- return false;
- } else if (type is VoidType || type is PointerType) {
- return false;
- } else if (type is ValueType) {
- if (type.nullable) {
- // nullable structs are heap allocated
- return true;
- }
-
- // TODO return true for structs with destroy
- return false;
- }
-
- return true;
- }
-
private void write_type (DataType type) {
write_string (type.to_qualified_string (current_scope));
}
return result;
}
+
+ public bool is_weak () {
+ if (this.value_owned) {
+ return false;
+ } else if (this is VoidType || this is PointerType) {
+ return false;
+ } else if (this is ValueType) {
+ if (this.nullable) {
+ // nullable structs are heap allocated
+ return true;
+ }
+
+ // TODO return true for structs with destroy
+ return false;
+ }
+
+ return true;
+ }
}
}
return null;
}
+
+ public string to_prototype_string (bool with_type_parameters = false) {
+ var proto = "%s %s (".printf (get_return_type ().to_string (), this.to_string ());
+
+ int i = 1;
+ foreach (FormalParameter param in get_parameters ()) {
+ if (i > 1) {
+ proto += ", ";
+ }
+
+ if (param.ellipsis) {
+ proto += "...";
+ continue;
+ }
+
+ if (param.direction == ParameterDirection.IN) {
+ if (param.variable_type.value_owned) {
+ proto += "owned ";
+ }
+ } else {
+ if (param.direction == ParameterDirection.REF) {
+ proto += "ref ";
+ } else if (param.direction == ParameterDirection.OUT) {
+ proto += "out ";
+ }
+ if (param.variable_type.is_weak ()) {
+ proto += "unowned ";
+ }
+ }
+
+ proto = "%s%s %s".printf (proto, param.variable_type.to_qualified_string (), param.name);
+
+ if (param.initializer != null) {
+ proto = "%s = %s".printf (proto, param.initializer.to_string ());
+ }
+
+ i++;
+ }
+
+ return proto + ")";
+ }
}
if (arg_it == null || !arg_it.next ()) {
if (param.initializer == null) {
+ var m = (MethodType) mtype;
expr.error = true;
- Report.error (expr.source_reference, "Too few arguments, method `%s' does not take %d arguments".printf (mtype.to_string (), args.size));
+ Report.error (expr.source_reference, "%d missing arguments for `%s'".printf (m.get_parameters ().size - args.size, m.to_prototype_string ()));
return false;
} else {
var invocation_expr = expr as MethodCall;
i++;
}
} else if (!ellipsis && arg_it != null && arg_it.next ()) {
+ var m = (MethodType) mtype;
expr.error = true;
- Report.error (expr.source_reference, "Too many arguments, method `%s' does not take %d arguments".printf (mtype.to_string (), args.size));
+ Report.error (expr.source_reference, "%d extra arguments for `%s'".printf (args.size - m.get_parameters ().size, m.to_prototype_string ()));
return false;
}