changeset 633:d208fc4291df

merge
author Tomas Lindquist Olsen <tomas.l.olsen@gmail.com>
date Wed, 01 Oct 2008 23:17:36 +0200
parents df196c8dea26 (current diff) 9fcb5f1a4c54 (diff)
children 0084d2c76b74
files
diffstat 1 files changed, 8 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/dmd/mtype.c	Wed Oct 01 23:17:14 2008 +0200
+++ b/dmd/mtype.c	Wed Oct 01 23:17:36 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