Commit 2707980d authored by Marc-André Lureau's avatar Marc-André Lureau Committed by Jürg Billeter

Better error message for invalid number of arguments

Fixes bug 608187.
parent ff63c4b8
......@@ -741,7 +741,7 @@ public class Vala.CodeWriter : CodeVisitor {
write_string ("class ");
}
if (is_weak (f.variable_type)) {
if (f.variable_type.is_weak ()) {
write_string ("weak ");
}
......@@ -836,7 +836,7 @@ public class Vala.CodeWriter : CodeVisitor {
} else if (param.direction == ParameterDirection.OUT) {
write_string ("out ");
}
if (is_weak (param.variable_type)) {
if (param.variable_type.is_weak ()) {
write_string ("unowned ");
}
}
......@@ -1823,31 +1823,13 @@ public class Vala.CodeWriter : CodeVisitor {
}
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));
}
......
......@@ -520,4 +520,22 @@ public abstract class Vala.DataType : CodeNode {
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;
}
}
......@@ -76,4 +76,45 @@ public class Vala.MethodType : DataType {
}
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 + ")";
}
}
......@@ -418,8 +418,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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;
......@@ -474,8 +475,9 @@ public class Vala.SemanticAnalyzer : CodeVisitor {
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;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment