changeset 630:bc83491463f0

Nicer error message on some invalid default args.
author Christian Kamm <kamm incasoftware de>
date Wed, 01 Oct 2008 21:14:15 +0200
parents e3c46bcce65f
children 9fcb5f1a4c54
files dmd/mtype.c
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mtype.c	Wed Oct 01 20:32:12 2008 +0200
+++ b/dmd/mtype.c	Wed Oct 01 21:14:15 2008 +0200
@@ -2934,6 +2934,14 @@
 		arg->defaultArg = arg->defaultArg->semantic(sc);
 		arg->defaultArg = resolveProperties(sc, arg->defaultArg);
 		arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type);
+
+		// make sure default arguments only use variables with lower protection
+		// this check only catches the common case that the default arg Exp is a VarExp
+		if(arg->defaultArg->op == TOKvar)
+		{   VarExp *ve = (VarExp *)arg->defaultArg;
+		    if(ve->var->protection < sc->protection)
+			error(loc, "default argument %s has stronger protection than function %s", ve->var->toChars(), toChars());
+		}
 	    }
 
 	    /* If arg turns out to be a tuple, the number of parameters may