From c4b523dc293f778284d926ea47af17d8e9126874 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Wed, 1 Oct 2008 21:14:15 +0200 Subject: [PATCH] Nicer error message on some invalid default args. --- dmd/mtype.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/dmd/mtype.c b/dmd/mtype.c index b0fa52b4..e7e10010 100644 --- a/dmd/mtype.c +++ b/dmd/mtype.c @@ -2934,6 +2934,14 @@ Type *TypeFunction::semantic(Loc loc, Scope *sc) 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