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