@@ -10604,6 +10604,35 @@ private extern (C++) final class ExpressionSemanticVisitor : Visitor
1060410604 if (exp.op == EXP.assign
1060510605 && exp.e1.checkModifiable(sc) == Modifiable.initialization)
1060610606 {
10607+ // Check common mistake of misspelled parameters in constructors,
10608+ // e.g. `this(int feild) { this.field = field; }`
10609+ if (auto dve1 = exp.e1.isDotVarExp)
10610+ if (auto dve2 = exp.e2.isDotVarExp)
10611+ if (sc.func && sc.func.parameters && dve1.e1.isThisExp && dve2.e1.isThisExp()
10612+ && dve1.var.ident.equals(dve2.var.ident))
10613+ {
10614+ // @@@DEPRECATED_2.121@@@
10615+ // Deprecated in 2.111, make it an error in 2.121
10616+ deprecation(exp.e1.loc, "cannot initialize field `%s` with itself", dve1.var.toChars());
10617+ auto findParameter(const(char)[] s, ref int cost)
10618+ {
10619+ foreach (p; *sc.func.parameters)
10620+ {
10621+ if (p.ident.toString == s)
10622+ {
10623+ cost = 1;
10624+ return p.ident.toString;
10625+ }
10626+ }
10627+ return null;
10628+ }
10629+ import dmd.root.speller : speller;
10630+ if (auto s = speller!findParameter(dve1.var.ident.toString))
10631+ {
10632+ deprecationSupplemental(sc.func.loc, "did you mean to use parameter `%.*s`?\n", s.fTuple.expand);
10633+ }
10634+ }
10635+
1060710636 //printf("[%s] change to init - %s\n", exp.loc.toChars(), exp.toChars());
1060810637 auto t = exp.type;
1060910638 exp = new ConstructExp(exp.loc, exp.e1, exp.e2);
0 commit comments