Mercurial > projects > dang
changeset 193:658178183018
Added error message for the case of calling a function pointer with wrong parameter count.
author | Anders Johnsen <skabet@gmail.com> |
---|---|
date | Fri, 25 Jul 2008 15:31:16 +0200 |
parents | fda35d57847e |
children | 08f68d684047 |
files | ast/Exp.d basic/Messages.d sema/TypeCheck.d |
diffstat | 3 files changed, 23 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/ast/Exp.d Fri Jul 25 15:00:54 2008 +0200 +++ b/ast/Exp.d Fri Jul 25 15:31:16 2008 +0200 @@ -110,6 +110,16 @@ return f.returnType; } + DType callerType() + { + DFunction f = new DFunction(new Identifier("function")); + f.returnType = type; + foreach (a ; args) + f.params ~= a.type; + + return f; + } + override CallExp simplify() { foreach (ref arg; args)
--- a/basic/Messages.d Fri Jul 25 15:00:54 2008 +0200 +++ b/basic/Messages.d Fri Jul 25 15:31:16 2008 +0200 @@ -46,6 +46,7 @@ NoMachingMethod, CannotReassignSArray, CanOnlyDerefPointers, + CannotCallMethod, // Strings InvalidStrPrefix, @@ -130,6 +131,7 @@ InvalidCaseValue : E(Err, "Case values must be integers"), CannotReassignSArray: E(Err, "Cannot reassign static arrays"), CanOnlyDerefPointers: E(Err, "Can only deref pointers, not '%0'"), + CannotCallMethod : E(Err, "Cannot call a method of type '%0' with '%1'"), // literals InvalidStrPrefix : E(Err, "Invalid string literal prefix"),
--- a/sema/TypeCheck.d Fri Jul 25 15:00:54 2008 +0200 +++ b/sema/TypeCheck.d Fri Jul 25 15:31:16 2008 +0200 @@ -218,7 +218,15 @@ } } else if (iden.type.isCallable) + { function_type = iden.type.asCallable(); + if (exp.args.length != function_type.params.length) + { + messages.report(CannotCallMethod, exp.loc) + .arg(iden.type.toString) + .arg(exp.callerType.toString); + } + } else assert(0, "Should not happen"); foreach (i, arg; exp.args) @@ -421,13 +429,14 @@ Symbol[] possible; Symbol perfect; + bool per, work; foreach (s ; available) { if (s.type.asFunction.params.length < arg_list.length) continue; - bool per = true; - bool work = true; + per = true; + work = true; foreach (i, arg; arg_list) {