comparison dmd/mtype.c @ 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 4435f57956e7
children 307ae566885f
comparison
equal deleted inserted replaced
628:e3c46bcce65f 630:bc83491463f0
2932 if (arg->defaultArg) 2932 if (arg->defaultArg)
2933 { 2933 {
2934 arg->defaultArg = arg->defaultArg->semantic(sc); 2934 arg->defaultArg = arg->defaultArg->semantic(sc);
2935 arg->defaultArg = resolveProperties(sc, arg->defaultArg); 2935 arg->defaultArg = resolveProperties(sc, arg->defaultArg);
2936 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type); 2936 arg->defaultArg = arg->defaultArg->implicitCastTo(sc, arg->type);
2937
2938 // make sure default arguments only use variables with lower protection
2939 // this check only catches the common case that the default arg Exp is a VarExp
2940 if(arg->defaultArg->op == TOKvar)
2941 { VarExp *ve = (VarExp *)arg->defaultArg;
2942 if(ve->var->protection < sc->protection)
2943 error(loc, "default argument %s has stronger protection than function %s", ve->var->toChars(), toChars());
2944 }
2937 } 2945 }
2938 2946
2939 /* If arg turns out to be a tuple, the number of parameters may 2947 /* If arg turns out to be a tuple, the number of parameters may
2940 * change. 2948 * change.
2941 */ 2949 */