2 * Performs the semantic3 stage, which deals with function bodies.
4 * Copyright: Copyright (C) 1999-2023 by The D Language Foundation, All Rights Reserved
5 * Authors: $(LINK2 https://www.digitalmars.com, Walter Bright)
6 * License: $(LINK2 https://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
7 * Source: $(LINK2 https://github.com/dlang/dmd/blob/master/src/dmd/semantic3.d, _semantic3.d)
8 * Documentation: https://dlang.org/phobos/dmd_semantic3.html
9 * Coverage: https://codecov.io/gh/dlang/dmd/src/master/src/dmd/semantic3.d
14 import core.stdc.stdio;
15 import core.stdc.string;
19 import dmd.arraytypes;
20 import dmd.astcodegen;
28 import dmd.declaration;
31 import dmd.dinterpret;
36 import dmd.dsymbolsem;
41 import dmd.expression;
42 import dmd.expressionsem;
46 import dmd.identifier;
58 import dmd.root.filename;
59 import dmd.common.outbuffer;
61 import dmd.root.rootobject;
63 import dmd.sideeffect;
64 import dmd.statementsem;
65 import dmd.staticassert;
70 import dmd.templateparamsem;
77 /*************************************
78 * Does semantic analysis on function bodies.
80 extern(C++) void semantic3(Dsymbol dsym, Scope* sc)
82 scope v = new Semantic3Visitor(sc);
86 private extern(C++) final class Semantic3Visitor : Visitor
88 alias visit = Visitor.visit;
96 override void visit(Dsymbol) {}
98 override void visit(TemplateInstance tempinst)
102 printf("TemplateInstance.semantic3('%s'), semanticRun = %d\n", tempinst.toChars(), tempinst.semanticRun);
104 //if (toChars()[0] == 'D') *(char*)0=0;
105 if (tempinst.semanticRun >= PASS.semantic3)
107 tempinst.semanticRun = PASS.semantic3;
108 if (tempinst.errors || !tempinst.members)
111 TemplateDeclaration tempdecl = tempinst.tempdecl.isTemplateDeclaration();
114 sc = tempdecl._scope;
115 sc = sc.push(tempinst.argsym);
116 sc = sc.push(tempinst);
118 sc.minst = tempinst.minst;
120 int needGagging = (tempinst.gagged && !global.gag);
121 uint olderrors = global.errors;
122 int oldGaggedErrors = -1; // dead-store to prevent spurious warning
123 /* If this is a gagged instantiation, gag errors.
124 * Future optimisation: If the results are actually needed, errors
125 * would already be gagged, so we don't really need to run semantic
129 oldGaggedErrors = global.startGagging();
131 for (size_t i = 0; i < tempinst.members.length; i++)
133 Dsymbol s = (*tempinst.members)[i];
135 if (tempinst.gagged && global.errors != olderrors)
139 if (global.errors != olderrors)
141 if (!tempinst.errors)
143 if (!tempdecl.literal)
144 tempinst.error(tempinst.loc, "error instantiating");
146 tempinst.tinst.printInstantiationTrace();
148 tempinst.errors = true;
151 global.endGagging(oldGaggedErrors);
157 override void visit(TemplateMixin tmix)
159 if (tmix.semanticRun >= PASS.semantic3)
161 tmix.semanticRun = PASS.semantic3;
164 printf("TemplateMixin.semantic3('%s')\n", tmix.toChars());
169 sc = sc.push(tmix.argsym);
172 uint olderrors = global.errors;
174 for (size_t i = 0; i < tmix.members.length; i++)
176 Dsymbol s = (*tmix.members)[i];
180 if (global.errors != olderrors)
181 errorSupplemental(tmix.loc, "parent scope from here: `mixin %s`", tmix.toChars());
187 override void visit(Module mod)
189 //printf("Module::semantic3('%s'): parent = %p\n", toChars(), parent);
190 if (mod.semanticRun != PASS.semantic2done)
192 mod.semanticRun = PASS.semantic3;
193 // Note that modules get their own scope, from scratch.
194 // This is so regardless of where in the syntax a module
195 // gets imported, it is unaffected by context.
196 Scope* sc = Scope.createGlobal(mod); // create root scope
197 //printf("Module = %p\n", sc.scopesym);
200 // Pass 3 semantic routines: do initializers and function bodies
201 for (size_t i = 0; i < mod.members.length; i++)
203 Dsymbol s = (*mod.members)[i];
204 //printf("Module %s: %s.semantic3()\n", toChars(), s.toChars());
207 mod.runDeferredSemantic2();
210 if (mod.userAttribDecl)
212 mod.userAttribDecl.semantic3(sc);
216 mod.semanticRun = PASS.semantic3done;
219 override void visit(FuncDeclaration funcdecl)
221 //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", funcdecl.kind(), funcdecl.toChars(), sc);
222 /* Determine if function should add `return 0;`
226 //printf("addReturn0()\n");
227 auto f = funcdecl.type.isTypeFunction();
230 if (sc.flags & SCOPE.Cfile && funcdecl.isCMain() && f.next.ty == Tint32)
233 return f.next.ty == Tvoid &&
234 (funcdecl.isMain() || global.params.betterC && funcdecl.isCMain());
237 VarDeclaration _arguments = null;
239 if (!funcdecl.parent)
243 //printf("FuncDeclaration::semantic3(%s '%s', sc = %p)\n", kind(), toChars(), sc);
246 if (funcdecl.errors || isError(funcdecl.parent))
248 funcdecl.errors = true;
250 // Mark that the return type could not be inferred
251 if (funcdecl.inferRetType)
253 assert(funcdecl.type);
254 auto tf = funcdecl.type.isTypeFunction();
256 // Only change the return type s.t. other analysis is
257 // still possible e.g. missmatched parameter types
259 tf.next = Type.terror;
263 //printf("FuncDeclaration::semantic3('%s.%s', %p, sc = %p, loc = %s)\n", funcdecl.parent.toChars(), funcdecl.toChars(), funcdecl, sc, funcdecl.loc.toChars());
265 //printf("storage class = x%x %x\n", sc.stc, storage_class);
266 //{ static int x; if (++x == 2) *(char*)0=0; }
267 //printf("\tlinkage = %d\n", sc.linkage);
269 if (funcdecl.ident == Id.assign && !funcdecl.inuse)
271 if (funcdecl.storage_class & STC.inference)
273 /* https://issues.dlang.org/show_bug.cgi?id=15044
274 * For generated opAssign function, any errors
275 * from its body need to be gagged.
277 uint oldErrors = global.startGagging();
279 funcdecl.semantic3(sc);
281 if (global.endGagging(oldErrors)) // if errors happened
283 // Disable generated opAssign, because some members forbid identity assignment.
284 funcdecl.storage_class |= STC.disable;
285 funcdecl.fbody = null; // remove fbody which contains the error
286 funcdecl.hasSemantic3Errors = false;
292 //printf(" sc.incontract = %d\n", (sc.flags & SCOPE.contract));
293 if (funcdecl.semanticRun >= PASS.semantic3)
295 funcdecl.semanticRun = PASS.semantic3;
296 funcdecl.hasSemantic3Errors = false;
298 if (!funcdecl.type || funcdecl.type.ty != Tfunction)
300 TypeFunction f = cast(TypeFunction)funcdecl.type;
301 if (!funcdecl.inferRetType && f.next.ty == Terror)
304 if (!funcdecl.fbody && funcdecl.inferRetType && !f.next)
306 funcdecl.error("has no function body with return type inference");
310 uint oldErrors = global.errors;
311 auto fds = FuncDeclSem3(funcdecl,sc);
313 fds.checkInContractOverrides();
315 // Remember whether we need to generate an 'out' contract.
316 immutable bool needEnsure = FuncDeclaration.needsFensure(funcdecl);
318 if (funcdecl.fbody || funcdecl.frequires || needEnsure)
320 /* Symbol table into which we place parameters and nested functions,
321 * solely to diagnose name collisions.
323 funcdecl.localsymtab = new DsymbolTable();
325 // Establish function scope
326 auto ss = new ScopeDsymbol(funcdecl.loc, null);
327 // find enclosing scope symbol, might skip symbol-less CTFE and/or FuncExp scopes
328 ss.parent = sc.inner().scopesym;
329 ss.endlinnum = funcdecl.endloc.linnum;
330 Scope* sc2 = sc.push(ss);
332 sc2.parent = funcdecl;
333 sc2.ctorflow.callSuper = CSX.none;
335 sc2.scontinue = null;
337 sc2.fes = funcdecl.fes;
338 sc2.linkage = funcdecl.isCsymbol() ? LINK.c : LINK.d;
339 sc2.stc &= STC.flowThruFunction;
340 sc2.visibility = Visibility(Visibility.Kind.public_);
341 sc2.explicitVisibility = 0;
342 sc2.aligndecl = null;
343 if (funcdecl.ident != Id.require && funcdecl.ident != Id.ensure)
344 sc2.flags = sc.flags & ~SCOPE.contract;
348 sc2.userAttribDecl = null;
349 if (sc2.intypeof == 1)
351 sc2.ctorflow.fieldinit = null;
353 /* Note: When a lambda is defined immediately under aggregate member
354 * scope, it should be contextless due to prevent interior pointers.
356 * // dg points 'this' - its interior pointer
357 * class C { int x; void delegate() dg = (){ this.x = 1; }; }
359 * However, lambdas could be used inside typeof, in order to check
360 * some expressions validity at compile time. For such case the lambda
361 * body can access aggregate instance members.
363 * class C { int x; static assert(is(typeof({ this.x = 1; }))); }
365 * To properly accept it, mark these lambdas as member functions.
367 if (auto fld = funcdecl.isFuncLiteralDeclaration())
369 if (auto ad = funcdecl.isMember2())
373 if (fld.tok == TOK.delegate_)
374 funcdecl.error("cannot be %s members", ad.kind());
376 fld.tok = TOK.function_;
380 if (fld.tok != TOK.function_)
381 fld.tok = TOK.delegate_;
386 funcdecl.declareThis(sc2);
388 // Reverts: https://issues.dlang.org/show_bug.cgi?id=5710
389 // No compiler supports this, and there was never any spec for it.
390 // @@@DEPRECATED_2.116@@@
391 // Deprecated in 2.096, can be made an error in 2.116.
392 // The deprecation period is longer than usual as dual-context
393 // functions may be widely used by dmd-compiled projects.
394 // It also gives more time for the implementation of dual-context
395 // functions to be reworked as a frontend-only feature.
396 if (funcdecl.hasDualContext())
398 funcdecl.deprecation("function requires a dual-context, which is deprecated");
399 if (auto ti = sc2.parent ? sc2.parent.isInstantiated() : null)
400 ti.printInstantiationTrace(Classification.deprecation);
403 //printf("[%s] ad = %p vthis = %p\n", loc.toChars(), ad, vthis);
404 //if (vthis) printf("\tvthis.type = %s\n", vthis.type.toChars());
406 // Declare hidden variable _arguments[] and _argptr
407 if (f.parameterList.varargs == VarArg.variadic)
409 if (f.linkage == LINK.d)
411 // Variadic arguments depend on Typeinfo being defined.
412 if (!global.params.useTypeInfo || !Type.dtypeinfo || !Type.typeinfotypelist)
414 if (!global.params.useTypeInfo)
415 funcdecl.error("D-style variadic functions cannot be used with -betterC");
416 else if (!Type.typeinfotypelist)
417 funcdecl.error("`object.TypeInfo_Tuple` could not be found, but is implicitly used in D-style variadic functions");
419 funcdecl.error("`object.TypeInfo` could not be found, but is implicitly used in D-style variadic functions");
423 // Declare _arguments[]
424 funcdecl.v_arguments = new VarDeclaration(funcdecl.loc, Type.typeinfotypelist.type, Id._arguments_typeinfo, null);
425 funcdecl.v_arguments.storage_class |= STC.temp | STC.parameter;
426 funcdecl.v_arguments.dsymbolSemantic(sc2);
427 sc2.insert(funcdecl.v_arguments);
428 funcdecl.v_arguments.parent = funcdecl;
430 //Type t = Type.dtypeinfo.type.constOf().arrayOf();
431 Type t = Type.dtypeinfo.type.arrayOf();
432 _arguments = new VarDeclaration(funcdecl.loc, t, Id._arguments, null);
433 _arguments.storage_class |= STC.temp;
434 _arguments.dsymbolSemantic(sc2);
435 sc2.insert(_arguments);
436 _arguments.parent = funcdecl;
438 if (f.linkage == LINK.d || f.parameterList.length)
441 Type t = target.va_listType(funcdecl.loc, sc);
442 // Init is handled in FuncDeclaration_toObjFile
443 funcdecl.v_argptr = new VarDeclaration(funcdecl.loc, t, Id._argptr, new VoidInitializer(funcdecl.loc));
444 funcdecl.v_argptr.storage_class |= STC.temp;
445 funcdecl.v_argptr.dsymbolSemantic(sc2);
446 sc2.insert(funcdecl.v_argptr);
447 funcdecl.v_argptr.parent = funcdecl;
451 /* Declare all the function parameters as variables
452 * and install them in parameters[]
454 if (const nparams = f.parameterList.length)
456 /* parameters[] has all the tuples removed, as the back end
457 * doesn't know about tuples
459 funcdecl.parameters = new VarDeclarations();
460 funcdecl.parameters.reserve(nparams);
461 foreach (i, fparam; f.parameterList)
463 Identifier id = fparam.ident;
464 StorageClass stc = 0;
467 /* Generate identifier for un-named parameter,
468 * because we need it later on.
470 fparam.ident = id = Identifier.generateId("_param_", i);
473 Type vtype = fparam.type;
474 auto v = new VarDeclaration(funcdecl.loc, vtype, id, null);
475 //printf("declaring parameter %s of type %s\n", v.toChars(), v.type.toChars());
476 stc |= STC.parameter;
477 if (f.parameterList.varargs == VarArg.typesafe && i + 1 == nparams)
482 stc |= fparam.storageClass & (STC.IOR | STC.return_ | STC.scope_ | STC.lazy_ | STC.final_ | STC.TYPECTOR | STC.nodtor | STC.returnScope | STC.register);
483 v.storage_class = stc;
484 v.dsymbolSemantic(sc2);
487 funcdecl.error("parameter `%s.%s` is already defined", funcdecl.toChars(), v.toChars());
488 funcdecl.errors = true;
491 funcdecl.parameters.push(v);
492 funcdecl.localsymtab.insert(v);
494 if (fparam.userAttribDecl)
495 v.userAttribDecl = fparam.userAttribDecl;
499 // Declare the tuple symbols and put them in the symbol table,
500 // but not in parameters[].
501 if (f.parameterList.parameters)
502 foreach (fparam; *f.parameterList.parameters)
505 continue; // never used, so ignore
507 if (fparam.type.ty != Ttuple)
510 TypeTuple t = cast(TypeTuple)fparam.type;
511 size_t dim = Parameter.dim(t.arguments);
512 auto exps = new Objects(dim);
513 foreach (j; 0 .. dim)
515 Parameter narg = Parameter.getNth(t.arguments, j);
517 VarDeclaration v = sc2.search(Loc.initial, narg.ident, null).isVarDeclaration();
519 (*exps)[j] = new VarExp(v.loc, v);
521 assert(fparam.ident);
522 auto v = new TupleDeclaration(funcdecl.loc, fparam.ident, exps);
523 //printf("declaring tuple %s\n", v.toChars());
526 funcdecl.error("parameter `%s.%s` is already defined", funcdecl.toChars(), v.toChars());
527 funcdecl.localsymtab.insert(v);
531 // Precondition invariant
532 Statement fpreinv = null;
533 if (funcdecl.addPreInvariant())
535 Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis);
537 fpreinv = new ExpStatement(Loc.initial, e);
540 // Postcondition invariant
541 Statement fpostinv = null;
542 if (funcdecl.addPostInvariant())
544 Expression e = addInvariant(funcdecl.isThis(), funcdecl.vthis);
546 fpostinv = new ExpStatement(Loc.initial, e);
549 // Pre/Postcondition contract
551 funcdecl.buildEnsureRequire();
554 if (needEnsure || funcdecl.addPostInvariant())
556 /* https://issues.dlang.org/show_bug.cgi?id=3657
557 * Set the correct end line number for fensure scope.
559 uint fensure_endlin = funcdecl.endloc.linnum;
560 if (funcdecl.fensure)
561 if (auto s = funcdecl.fensure.isScopeStatement())
562 fensure_endlin = s.endloc.linnum;
564 if ((needEnsure && global.params.useOut == CHECKENABLE.on) || fpostinv)
566 funcdecl.returnLabel = funcdecl.searchLabel(Id.returnLabel);
569 // scope of out contract (need for vresult.semantic)
570 auto sym = new ScopeDsymbol(funcdecl.loc, null);
571 sym.parent = sc2.scopesym;
572 sym.endlinnum = fensure_endlin;
573 scout = sc2.push(sym);
578 auto sym = new ScopeDsymbol(funcdecl.loc, null);
579 sym.parent = sc2.scopesym;
580 sym.endlinnum = funcdecl.endloc.linnum;
583 auto ad2 = funcdecl.isMemberLocal();
585 /* If this is a class constructor
587 if (ad2 && funcdecl.isCtorDeclaration())
589 sc2.ctorflow.allocFieldinit(ad2.fields.length);
590 foreach (v; ad2.fields)
596 bool inferRef = (f.isref && (funcdecl.storage_class & STC.auto_));
598 funcdecl.fbody = funcdecl.fbody.statementSemantic(sc2);
600 funcdecl.fbody = new CompoundStatement(Loc.initial, new Statements());
602 if (funcdecl.isNaked())
604 fpreinv = null; // can't accommodate with no stack frame
608 assert(funcdecl.type == f || (funcdecl.type.ty == Tfunction && f.purity == PURE.impure && (cast(TypeFunction)funcdecl.type).purity >= PURE.fwdref));
609 f = cast(TypeFunction)funcdecl.type;
611 if (funcdecl.inferRetType)
613 // If no return type inferred yet, then infer a void
616 if (f.checkRetType(funcdecl.loc))
617 funcdecl.fbody = new ErrorStatement();
619 funcdecl.checkMain(); // Check main() parameters and return type
623 f.next.checkComplexTransition(funcdecl.loc, sc);
625 if (funcdecl.returns && !funcdecl.fbody.isErrorStatement())
627 for (size_t i = 0; i < funcdecl.returns.length;)
629 Expression exp = (*funcdecl.returns)[i].exp;
630 if (exp.op == EXP.variable && (cast(VarExp)exp).var == funcdecl.vresult)
633 exp.type = Type.tint32;
636 // Remove `return vresult;` from returns
637 funcdecl.returns.remove(i);
640 if (inferRef && f.isref && !exp.type.constConv(f.next)) // https://issues.dlang.org/show_bug.cgi?id=13336
645 if (f.isref) // Function returns a reference
647 if (funcdecl.storage_class & STC.auto_)
648 funcdecl.storage_class &= ~STC.auto_;
652 if (!target.isReturnOnStack(f, funcdecl.needThis()) || !funcdecl.checkNRVO())
653 funcdecl.isNRVO = false;
655 if (funcdecl.fbody.isErrorStatement())
658 else if (funcdecl.isStaticCtorDeclaration())
660 /* It's a static constructor. Ensure that all
661 * ctor consts were initialized.
663 ScopeDsymbol pd = funcdecl.toParent().isScopeDsymbol();
664 for (size_t i = 0; i < pd.members.length; i++)
666 Dsymbol s = (*pd.members)[i];
667 s.checkCtorConstInit();
670 else if (ad2 && funcdecl.isCtorDeclaration())
672 ClassDeclaration cd = ad2.isClassDeclaration();
674 // Verify that all the ctorinit fields got initialized
675 if (!(sc2.ctorflow.callSuper & CSX.this_ctor))
677 foreach (i, v; ad2.fields)
679 if (v.isThisDeclaration())
683 /* Current bugs in the flow analysis:
684 * 1. union members should not produce error messages even if
686 * 2. structs should recognize delegating opAssign calls as well
687 * as delegating calls to other constructors
689 if (v.isCtorinit() && !v.type.isMutable() && cd)
690 funcdecl.error("missing initializer for %s field `%s`", MODtoChars(v.type.mod), v.toChars());
691 else if (v.storage_class & STC.nodefaultctor)
692 error(funcdecl.loc, "field `%s` must be initialized in constructor", v.toChars());
693 else if (v.type.needsNested())
694 error(funcdecl.loc, "field `%s` must be initialized in constructor, because it is nested struct", v.toChars());
698 bool mustInit = (v.storage_class & STC.nodefaultctor || v.type.needsNested());
699 if (mustInit && !(sc2.ctorflow.fieldinit[i].csx & CSX.this_ctor))
701 funcdecl.error("field `%s` must be initialized but skipped", v.toChars());
706 sc2.ctorflow.freeFieldinit();
708 if (cd && !(sc2.ctorflow.callSuper & CSX.any_ctor) && cd.baseClass && cd.baseClass.ctor)
710 sc2.ctorflow.callSuper = CSX.none;
712 // Insert implicit super() at start of fbody
713 Type tthis = ad2.type.addMod(funcdecl.vthis.type.mod);
714 FuncDeclaration fd = resolveFuncCall(Loc.initial, sc2, cd.baseClass.ctor, null, tthis, ArgumentList(), FuncResolveFlag.quiet);
717 funcdecl.error("no match for implicit `super()` call in constructor");
719 else if (fd.storage_class & STC.disable)
721 funcdecl.error("cannot call `super()` implicitly because it is annotated with `@disable`");
725 Expression e1 = new SuperExp(Loc.initial);
726 Expression e = new CallExp(Loc.initial, e1);
727 e = e.expressionSemantic(sc2);
728 Statement s = new ExpStatement(Loc.initial, e);
729 funcdecl.fbody = new CompoundStatement(Loc.initial, s, funcdecl.fbody);
732 //printf("ctorflow.callSuper = x%x\n", sc2.ctorflow.callSuper);
735 /* https://issues.dlang.org/show_bug.cgi?id=17502
736 * Wait until after the return type has been inferred before
737 * generating the contracts for this function, and merging contracts
740 * https://issues.dlang.org/show_bug.cgi?id=17893
741 * However should take care to generate this before inferered
742 * function attributes are applied, such as 'nothrow'.
744 * This was originally at the end of the first semantic pass, but
745 * required a fix-up to be done here for the '__result' variable
746 * type of __ensure() inside auto functions, but this didn't work
747 * if the out parameter was implicit.
749 funcdecl.buildEnsureRequire();
751 // Check for errors related to 'nothrow'.
752 const blockexit = funcdecl.fbody.blockExit(funcdecl, f.isnothrow);
753 if (f.isnothrow && blockexit & BE.throw_)
754 error(funcdecl.loc, "%s `%s` may throw but is marked as `nothrow`", funcdecl.kind(), funcdecl.toPrettyChars());
756 if (!(blockexit & (BE.throw_ | BE.halt) || funcdecl.hasCatches))
758 /* Don't generate unwind tables for this function
759 * https://issues.dlang.org/show_bug.cgi?id=17997
761 funcdecl.hasNoEH = true;
764 if (funcdecl.nothrowInprocess)
766 if (funcdecl.type == f)
767 f = cast(TypeFunction)f.copy();
768 f.isnothrow = !(blockexit & BE.throw_);
771 if (funcdecl.fbody.isErrorStatement())
774 else if (ad2 && funcdecl.isCtorDeclaration())
780 if (blockexit & BE.fallthru)
782 Statement s = new ReturnStatement(funcdecl.loc, null);
783 s = s.statementSemantic(sc2);
784 funcdecl.fbody = new CompoundStatement(funcdecl.loc, funcdecl.fbody, s);
785 funcdecl.hasReturnExp |= (funcdecl.hasReturnExp & 1 ? 16 : 1);
788 else if (funcdecl.fes)
790 // For foreach(){} body, append a return 0;
791 if (blockexit & BE.fallthru)
793 Expression e = IntegerExp.literal!0;
794 Statement s = new ReturnStatement(Loc.initial, e);
795 funcdecl.fbody = new CompoundStatement(Loc.initial, funcdecl.fbody, s);
796 funcdecl.hasReturnExp |= (funcdecl.hasReturnExp & 1 ? 16 : 1);
798 assert(!funcdecl.returnLabel);
800 else if (f.next.toBasetype().ty == Tnoreturn)
802 // Fallthrough despite being declared as noreturn? return is already rejected when evaluating the ReturnStatement
803 if (blockexit & BE.fallthru)
805 funcdecl.error("is typed as `%s` but does return", f.next.toChars());
806 funcdecl.loc.errorSupplemental("`noreturn` functions must either throw, abort or loop indefinitely");
811 const(bool) inlineAsm = (funcdecl.hasReturnExp & 8) != 0;
812 if ((blockexit & BE.fallthru) && f.next.ty != Tvoid && !inlineAsm && !(sc.flags & SCOPE.Cfile))
814 if (!funcdecl.hasReturnExp)
815 funcdecl.error("has no `return` statement, but is expected to return a value of type `%s`", f.next.toChars());
817 funcdecl.error("no `return exp;` or `assert(0);` at end of function");
821 if (funcdecl.returns)
823 bool implicit0 = addReturn0();
824 Type tret = implicit0 ? Type.tint32 : f.next;
825 assert(tret.ty != Tvoid);
826 if (funcdecl.vresult || funcdecl.returnLabel)
827 funcdecl.buildResultVar(scout ? scout : sc2, tret);
829 /* Cannot move this loop into NrvoWalker, because
830 * returns[i] may be in the nested delegate for foreach-body.
832 for (size_t i = 0; i < funcdecl.returns.length; i++)
834 ReturnStatement rs = (*funcdecl.returns)[i];
835 Expression exp = rs.exp;
836 if (exp.op == EXP.error)
838 if (tret.ty == Terror)
840 // https://issues.dlang.org/show_bug.cgi?id=13702
841 exp = checkGC(sc2, exp);
845 /* If the expression in the return statement (exp) cannot be implicitly
846 * converted to the return type (tret) of the function and if the
847 * type of the expression is type isolated, then it may be possible
848 * that a promotion to `immutable` or `inout` (through a cast) will
849 * match the return type.
851 if (!exp.implicitConvTo(tret) && funcdecl.isTypeIsolated(exp.type))
853 /* https://issues.dlang.org/show_bug.cgi?id=20073
855 * The problem is that if the type of the returned expression (exp.type)
856 * is an aggregated declaration with an alias this, the alias this may be
857 * used for the conversion testing without it being an isolated type.
859 * To make sure this does not happen, we can test here the implicit conversion
860 * only for the aggregated declaration type by using `implicitConvToWithoutAliasThis`.
861 * The implicit conversion with alias this is taken care of later.
863 AggregateDeclaration aggDecl = isAggregate(exp.type);
867 if (aggDecl && aggDecl.aliasthis)
870 tclass = exp.type.isTypeClass();
872 tstruct = exp.type.isTypeStruct();
873 assert(tclass || tstruct);
879 if ((cast(TypeClass)(exp.type.immutableOf())).implicitConvToWithoutAliasThis(tret))
880 exp = exp.castTo(sc2, exp.type.immutableOf());
881 else if ((cast(TypeClass)(exp.type.wildOf())).implicitConvToWithoutAliasThis(tret))
882 exp = exp.castTo(sc2, exp.type.wildOf());
886 if ((cast(TypeStruct)exp.type.immutableOf()).implicitConvToWithoutAliasThis(tret))
887 exp = exp.castTo(sc2, exp.type.immutableOf());
888 else if ((cast(TypeStruct)exp.type.immutableOf()).implicitConvToWithoutAliasThis(tret))
889 exp = exp.castTo(sc2, exp.type.wildOf());
894 if (exp.type.immutableOf().implicitConvTo(tret))
895 exp = exp.castTo(sc2, exp.type.immutableOf());
896 else if (exp.type.wildOf().implicitConvTo(tret))
897 exp = exp.castTo(sc2, exp.type.wildOf());
901 const hasCopyCtor = exp.type.ty == Tstruct && (cast(TypeStruct)exp.type).sym.hasCopyCtor;
902 // if a copy constructor is present, the return type conversion will be handled by it
903 if (!(hasCopyCtor && exp.isLvalue()))
905 if (f.isref && !MODimplicitConv(exp.type.mod, tret.mod) && !tret.isTypeSArray())
906 error(exp.loc, "expression `%s` of type `%s` is not implicitly convertible to return type `ref %s`",
907 exp.toChars(), exp.type.toChars(), tret.toChars());
909 exp = exp.implicitCastTo(sc2, tret);
914 // Function returns a reference
915 exp = exp.toLvalue(sc2, exp);
916 checkReturnEscapeRef(sc2, exp, false);
917 exp = exp.optimize(WANTvalue, /*keepLvalue*/ true);
921 exp = exp.optimize(WANTvalue);
923 /* https://issues.dlang.org/show_bug.cgi?id=10789
924 * If NRVO is not possible, all returned lvalues should call their postblits.
926 if (!funcdecl.isNRVO())
927 exp = doCopyOrMove(sc2, exp, f.next);
929 if (tret.hasPointers())
930 checkReturnEscape(sc2, exp, false);
933 exp = checkGC(sc2, exp);
935 if (funcdecl.vresult)
937 // Create: return vresult = exp;
938 exp = new BlitExp(rs.loc, funcdecl.vresult, exp);
939 exp.type = funcdecl.vresult.type;
942 exp = Expression.combine(exp, new IntegerExp(rs.caseDim));
944 else if (funcdecl.tintro && !tret.equals(funcdecl.tintro.nextOf()))
946 exp = exp.implicitCastTo(sc2, funcdecl.tintro.nextOf());
951 if (funcdecl.nrvo_var || funcdecl.returnLabel)
953 scope NrvoWalker nw = new NrvoWalker();
956 nw.visitStmt(funcdecl.fbody);
962 if (global.params.inclusiveInContracts)
964 funcdecl.frequire = funcdecl.mergeFrequireInclusivePreview(
965 funcdecl.frequire, funcdecl.fdrequireParams);
969 funcdecl.frequire = funcdecl.mergeFrequire(funcdecl.frequire, funcdecl.fdrequireParams);
971 funcdecl.fensure = funcdecl.mergeFensure(funcdecl.fensure, Id.result, funcdecl.fdensureParams);
973 Statement freq = funcdecl.frequire;
974 Statement fens = funcdecl.fensure;
976 /* Do the semantic analysis on the [in] preconditions and
977 * [out] postconditions.
979 immutable bool isnothrow = f.isnothrow && !funcdecl.nothrowInprocess;
982 /* frequire is composed of the [in] contracts
984 auto sym = new ScopeDsymbol(funcdecl.loc, null);
985 sym.parent = sc2.scopesym;
986 sym.endlinnum = funcdecl.endloc.linnum;
988 sc2.flags = (sc2.flags & ~SCOPE.contract) | SCOPE.require;
990 // BUG: need to error if accessing out parameters
991 // BUG: need to disallow returns
992 // BUG: verify that all in and ref parameters are read
993 freq = freq.statementSemantic(sc2);
995 // @@@DEPRECATED_2.111@@@ - pass `isnothrow` instead of `false` to print a more detailed error msg`
996 const blockExit = freq.blockExit(funcdecl, false);
997 if (blockExit & BE.throw_)
1000 // @@@DEPRECATED_2.111@@@
1001 // Deprecated in 2.101, can be made an error in 2.111
1002 deprecation(funcdecl.loc, "`%s`: `in` contract may throw but function is marked as `nothrow`",
1003 funcdecl.toPrettyChars());
1004 else if (funcdecl.nothrowInprocess)
1005 f.isnothrow = false;
1008 funcdecl.hasNoEH = false;
1012 if (global.params.useIn == CHECKENABLE.off)
1018 /* fensure is composed of the [out] contracts
1020 if (f.next.ty == Tvoid && funcdecl.fensures)
1022 foreach (e; *funcdecl.fensures)
1026 funcdecl.error(e.ensure.loc, "`void` functions have no result");
1033 sc2.flags = (sc2.flags & ~SCOPE.contract) | SCOPE.ensure;
1035 // BUG: need to disallow returns and throws
1037 if (funcdecl.fensure && f.next.ty != Tvoid)
1038 funcdecl.buildResultVar(scout, f.next);
1040 fens = fens.statementSemantic(sc2);
1042 // @@@DEPRECATED_2.111@@@ - pass `isnothrow` instead of `false` to print a more detailed error msg`
1043 const blockExit = fens.blockExit(funcdecl, false);
1044 if (blockExit & BE.throw_)
1047 // @@@DEPRECATED_2.111@@@
1048 // Deprecated in 2.101, can be made an error in 2.111
1049 deprecation(funcdecl.loc, "`%s`: `out` contract may throw but function is marked as `nothrow`",
1050 funcdecl.toPrettyChars());
1051 else if (funcdecl.nothrowInprocess)
1052 f.isnothrow = false;
1055 funcdecl.hasNoEH = false;
1059 if (global.params.useOut == CHECKENABLE.off)
1062 if (funcdecl.fbody && funcdecl.fbody.isErrorStatement())
1067 auto a = new Statements();
1068 // Merge in initialization of 'out' parameters
1069 if (funcdecl.parameters)
1071 for (size_t i = 0; i < funcdecl.parameters.length; i++)
1073 VarDeclaration v = (*funcdecl.parameters)[i];
1074 if (v.storage_class & STC.out_)
1078 v.error("zero-length `out` parameters are not allowed.");
1081 ExpInitializer ie = v._init.isExpInitializer();
1083 if (auto iec = ie.exp.isConstructExp())
1085 // construction occurred in parameter processing
1086 auto ec = new AssignExp(iec.loc, iec.e1, iec.e2);
1090 a.push(new ExpStatement(Loc.initial, ie.exp));
1097 /* Advance to elements[] member of TypeInfo_Tuple with:
1098 * _arguments = v_arguments.elements;
1100 Expression e = new VarExp(Loc.initial, funcdecl.v_arguments);
1101 e = new DotIdExp(Loc.initial, e, Id.elements);
1102 e = new ConstructExp(Loc.initial, _arguments, e);
1103 e = e.expressionSemantic(sc2);
1105 _arguments._init = new ExpInitializer(Loc.initial, e);
1106 auto de = new DeclarationExp(Loc.initial, _arguments);
1107 a.push(new ExpStatement(Loc.initial, de));
1110 // Merge contracts together with body into one compound statement
1112 if (freq || fpreinv)
1117 freq = new CompoundStatement(Loc.initial, freq, fpreinv);
1123 a.push(funcdecl.fbody);
1125 if (fens || fpostinv)
1130 fens = new CompoundStatement(Loc.initial, fpostinv, fens);
1132 auto ls = new LabelStatement(Loc.initial, Id.returnLabel, fens);
1133 funcdecl.returnLabel.statement = ls;
1134 a.push(funcdecl.returnLabel.statement);
1136 if (f.next.ty != Tvoid && funcdecl.vresult)
1138 // Create: return vresult;
1139 Expression e = new VarExp(Loc.initial, funcdecl.vresult);
1140 if (funcdecl.tintro)
1142 e = e.implicitCastTo(sc, funcdecl.tintro.nextOf());
1143 e = e.expressionSemantic(sc);
1145 auto s = new ReturnStatement(Loc.initial, e);
1151 // Add a return 0; statement
1152 Statement s = new ReturnStatement(Loc.initial, IntegerExp.literal!0);
1156 Statement sbody = new CompoundStatement(Loc.initial, a);
1158 /* Append destructor calls for parameters as finally blocks.
1160 if (funcdecl.parameters)
1162 // check if callee destroys arguments
1163 const bool paramsNeedDtor = target.isCalleeDestroyingArgs(f);
1165 foreach (v; *funcdecl.parameters)
1167 if (v.isReference() || (v.storage_class & STC.lazy_))
1169 if (v.needsScopeDtor())
1171 v.storage_class |= STC.nodtor;
1172 if (!paramsNeedDtor)
1175 // same with ExpStatement.scopeCode()
1176 Statement s = new DtorExpStatement(Loc.initial, v.edtor, v);
1178 s = s.statementSemantic(sc2);
1180 const blockexit = s.blockExit(funcdecl, isnothrow);
1181 if (blockexit & BE.throw_)
1183 funcdecl.hasNoEH = false;
1185 error(funcdecl.loc, "%s `%s` may throw but is marked as `nothrow`", funcdecl.kind(), funcdecl.toPrettyChars());
1186 else if (funcdecl.nothrowInprocess)
1187 f.isnothrow = false;
1190 if (sbody.blockExit(funcdecl, f.isnothrow) == BE.fallthru)
1191 sbody = new CompoundStatement(Loc.initial, sbody, s);
1193 sbody = new TryFinallyStatement(Loc.initial, sbody, s);
1197 // from this point on all possible 'throwers' are checked
1198 funcdecl.nothrowInprocess = false;
1200 if (funcdecl.isSynchronized())
1202 /* Wrap the entire function body in a synchronized statement
1204 ClassDeclaration cd = funcdecl.toParentDecl().isClassDeclaration();
1207 if (target.libraryObjectMonitors(funcdecl, sbody))
1210 if (funcdecl.isStatic())
1212 // The monitor is in the ClassInfo
1213 vsync = new DotIdExp(funcdecl.loc, symbolToExp(cd, funcdecl.loc, sc2, false), Id.classinfo);
1217 // 'this' is the monitor
1218 vsync = new VarExp(funcdecl.loc, funcdecl.vthis);
1219 if (funcdecl.hasDualContext())
1221 vsync = new PtrExp(funcdecl.loc, vsync);
1222 vsync = new IndexExp(funcdecl.loc, vsync, IntegerExp.literal!0);
1225 sbody = new PeelStatement(sbody); // don't redo semantic()
1226 sbody = new SynchronizedStatement(funcdecl.loc, vsync, sbody);
1227 sbody = sbody.statementSemantic(sc2);
1232 funcdecl.error("synchronized function `%s` must be a member of a class", funcdecl.toChars());
1236 // If declaration has no body, don't set sbody to prevent incorrect codegen.
1237 if (funcdecl.fbody || funcdecl.allowsContractWithoutBody())
1238 funcdecl.fbody = sbody;
1241 // Check for undefined labels
1242 if (funcdecl.labtab)
1243 foreach (keyValue; funcdecl.labtab.tab.asRange)
1245 //printf(" KV: %s = %s\n", keyValue.key.toChars(), keyValue.value.toChars());
1246 LabelDsymbol label = cast(LabelDsymbol)keyValue.value;
1247 if (!label.statement && (!label.deleted || label.iasm))
1249 funcdecl.error(label.loc, "label `%s` is undefined", label.toChars());
1253 // Fix up forward-referenced gotos
1254 if (funcdecl.gotos && !funcdecl.isCsymbol())
1256 for (size_t i = 0; i < funcdecl.gotos.length; ++i)
1258 (*funcdecl.gotos)[i].checkLabel();
1262 if (funcdecl.isNaked() && (funcdecl.fensures || funcdecl.frequires))
1263 funcdecl.error("naked assembly functions with contracts are not supported");
1265 sc2.ctorflow.callSuper = CSX.none;
1269 if (funcdecl.checkClosure())
1271 // We should be setting errors here instead of relying on the global error count.
1275 /* If function survived being marked as impure, then it is pure
1277 if (funcdecl.purityInprocess)
1279 funcdecl.purityInprocess = false;
1280 if (funcdecl.type == f)
1281 f = cast(TypeFunction)f.copy();
1282 f.purity = PURE.fwdref;
1285 if (funcdecl.safetyInprocess)
1287 funcdecl.safetyInprocess = false;
1288 if (funcdecl.type == f)
1289 f = cast(TypeFunction)f.copy();
1290 f.trust = TRUST.safe;
1293 if (funcdecl.nogcInprocess)
1295 funcdecl.nogcInprocess = false;
1296 if (funcdecl.type == f)
1297 f = cast(TypeFunction)f.copy();
1301 finishScopeParamInference(funcdecl, f);
1303 // reset deco to apply inference result to mangled name
1304 if (f != funcdecl.type)
1307 // Do semantic type AFTER pure/nothrow inference.
1308 if (!f.deco && funcdecl.ident != Id.xopEquals && funcdecl.ident != Id.xopCmp)
1311 if (funcdecl.isCtorDeclaration()) // https://issues.dlang.org/show_bug.cgi?id=#15665
1314 sc.linkage = funcdecl._linkage; // https://issues.dlang.org/show_bug.cgi?id=8496
1315 funcdecl.type = f.typeSemantic(funcdecl.loc, sc);
1319 // Check `extern(C++)` functions for invalid the return/parameter types
1320 if (funcdecl._linkage == LINK.cpp)
1322 static bool isCppNonMappableType(Type type, Parameter param = null, Type origType = null)
1324 // Don't allow D `immutable` and `shared` types to be interfaced with C++
1325 if (type.isImmutable() || type.isShared())
1327 else if (Type cpptype = target.cpp.parameterType(type))
1330 if (origType is null)
1333 // Permit types that are handled by toCppMangle. This list should be kept in sync with
1334 // each visit method in dmd.cppmangle and dmd.cppmanglewin.
1351 if (!origType.isTypePointer())
1356 if (!type.isTypeBasic())
1361 // Descend to the enclosing type
1362 if (auto tnext = type.nextOf())
1363 return isCppNonMappableType(tnext, param, origType);
1367 if (isCppNonMappableType(f.next.toBasetype()))
1369 funcdecl.error("cannot return type `%s` because its linkage is `extern(C++)`", f.next.toChars());
1370 funcdecl.errors = true;
1372 foreach (i, param; f.parameterList)
1374 if (isCppNonMappableType(param.type.toBasetype(), param))
1376 funcdecl.error("cannot have parameter of type `%s` because its linkage is `extern(C++)`", param.type.toChars());
1377 if (param.type.toBasetype().isTypeSArray())
1378 errorSupplemental(funcdecl.loc, "perhaps use a `%s*` type instead",
1379 param.type.nextOf().mutableOf().unSharedOf().toChars());
1380 funcdecl.errors = true;
1386 if (global.params.useDIP1021 && funcdecl.fbody && funcdecl.type.ty != Terror &&
1387 funcdecl.type.isTypeFunction().islive)
1392 /* If this function had instantiated with gagging, error reproduction will be
1393 * done by TemplateInstance::semantic.
1394 * Otherwise, error gagging should be temporarily ungagged by functionSemantic3.
1396 funcdecl.semanticRun = PASS.semantic3done;
1397 if ((global.errors != oldErrors) || (funcdecl.fbody && funcdecl.fbody.isErrorStatement()))
1398 funcdecl.hasSemantic3Errors = true;
1400 funcdecl.hasSemantic3Errors = false;
1401 if (funcdecl.type.ty == Terror)
1402 funcdecl.errors = true;
1403 //printf("-FuncDeclaration::semantic3('%s.%s', sc = %p, loc = %s)\n", funcdecl.parent.toChars(), funcdecl.toChars(), sc, funcdecl.loc.toChars());
1407 override void visit(CtorDeclaration ctor)
1409 //printf("CtorDeclaration()\n%s\n", ctor.fbody.toChars());
1410 if (ctor.semanticRun >= PASS.semantic3)
1413 /* If any of the fields of the aggregate have a destructor, add
1414 * scope (failure) { this.fieldDtor(); }
1415 * as the first statement of the constructor (unless the constructor
1416 * doesn't define a body - @disable, extern)
1417 *.It is not necessary to add it after
1418 * each initialization of a field, because destruction of .init constructed
1419 * structs should be benign.
1420 * https://issues.dlang.org/show_bug.cgi?id=14246
1422 AggregateDeclaration ad = ctor.isMemberDecl();
1423 if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields || global.params.betterC || ctor.type.toTypeFunction.isnothrow)
1424 return visit(cast(FuncDeclaration)ctor);
1429 Expression e = new ThisExp(ctor.loc);
1430 e.type = ad.type.mutableOf();
1431 e = new DotVarExp(ctor.loc, e, ad.fieldDtor, false);
1432 auto ce = new CallExp(ctor.loc, e);
1433 auto sexp = new ExpStatement(ctor.loc, ce);
1434 auto ss = new ScopeStatement(ctor.loc, sexp, ctor.loc);
1436 // @@@DEPRECATED_2.106@@@
1437 // Allow negligible attribute violations to allow for a smooth
1438 // transition. Remove this after the usual deprecation period
1440 if (global.params.dtorFields == FeatureState.default_)
1442 auto ctf = cast(TypeFunction) ctor.type;
1443 auto dtf = cast(TypeFunction) ad.fieldDtor.type;
1445 const ngErr = ctf.isnogc && !dtf.isnogc;
1446 const puErr = ctf.purity && !dtf.purity;
1447 const saErr = ctf.trust == TRUST.safe && dtf.trust <= TRUST.system;
1449 if (ngErr || puErr || saErr)
1451 // storage_class is apparently not set for dtor & ctor
1454 (ngErr ? STC.nogc : 0) |
1455 (puErr ? STC.pure_ : 0) |
1456 (saErr ? STC.system : 0)
1458 ctor.loc.deprecation("`%s` has stricter attributes than its destructor (`%s`)", ctor.toPrettyChars(), ob.peekChars());
1459 ctor.loc.deprecationSupplemental("The destructor will be called if an exception is thrown");
1460 ctor.loc.deprecationSupplemental("Either make the constructor `nothrow` or adjust the field destructors");
1462 ce.ignoreAttributes = true;
1469 * try { ctor.fbody; }
1470 * catch (Exception __o)
1471 * { this.fieldDtor(); throw __o; }
1472 * This differs from the alternate scope(failure) version in that an Exception
1473 * is caught rather than a Throwable. This enables the optimization whereby
1474 * the try-catch can be removed if ctor.fbody is nothrow. (nothrow only
1475 * applies to Exception.)
1477 Identifier id = Identifier.generateId("__o");
1478 auto ts = new ThrowStatement(ctor.loc, new IdentifierExp(ctor.loc, id));
1479 auto handler = new CompoundStatement(ctor.loc, ss, ts);
1481 auto catches = new Catches();
1482 auto ctch = new Catch(ctor.loc, getException(), id, handler);
1485 ctor.fbody = new TryCatchStatement(ctor.loc, ctor.fbody, catches);
1490 * scope (failure) { this.fieldDtor(); }
1491 * Hopefully we can use this version someday when scope(failure) catches
1492 * Exception instead of Throwable.
1494 auto s = new ScopeGuardStatement(ctor.loc, TOK.onScopeFailure, ss);
1495 ctor.fbody = new CompoundStatement(ctor.loc, s, ctor.fbody);
1497 visit(cast(FuncDeclaration)ctor);
1501 override void visit(Nspace ns)
1503 if (ns.semanticRun >= PASS.semantic3)
1505 ns.semanticRun = PASS.semantic3;
1508 printf("Nspace::semantic3('%s')\n", ns.toChars());
1514 sc.linkage = LINK.cpp;
1515 foreach (s; *ns.members)
1522 override void visit(AttribDeclaration ad)
1524 Dsymbols* d = ad.include(sc);
1528 Scope* sc2 = ad.newScope(sc);
1529 for (size_t i = 0; i < d.length; i++)
1531 Dsymbol s = (*d)[i];
1538 override void visit(AggregateDeclaration ad)
1540 //printf("AggregateDeclaration::semantic3(sc=%p, %s) type = %s, errors = %d\n", sc, toChars(), type.toChars(), errors);
1544 StructDeclaration sd = ad.isStructDeclaration();
1545 if (!sc) // from runDeferredSemantic3 for TypeInfo generation
1548 sd.semanticTypeInfoMembers();
1552 auto sc2 = ad.newScope(sc);
1554 for (size_t i = 0; i < ad.members.length; i++)
1556 Dsymbol s = (*ad.members)[i];
1562 // Instantiate RTInfo!S to provide a pointer bitmap for the GC
1563 // Don't do it in -betterC or on unused deprecated / error types
1564 if (!ad.getRTInfo && global.params.useTypeInfo && Type.rtinfo &&
1565 (!ad.isDeprecated() || global.params.useDeprecated != DiagnosticReporting.error) &&
1566 (ad.type && ad.type.ty != Terror))
1568 // Evaluate: RTinfo!type
1569 auto tiargs = new Objects();
1570 tiargs.push(ad.type);
1571 auto ti = new TemplateInstance(ad.loc, Type.rtinfo, tiargs);
1573 Scope* sc3 = ti.tempdecl._scope.startCTFE();
1574 sc3.tinst = sc.tinst;
1575 sc3.minst = sc.minst;
1576 if (ad.isDeprecated())
1577 sc3.stc |= STC.deprecated_;
1579 ti.dsymbolSemantic(sc3);
1582 auto e = symbolToExp(ti.toAlias(), Loc.initial, sc3, false);
1586 e = e.ctfeInterpret();
1590 sd.semanticTypeInfoMembers();
1591 ad.semanticRun = PASS.semantic3done;
1595 private struct FuncDeclSem3
1597 // The FuncDeclaration subject to Semantic analysis
1598 FuncDeclaration funcdecl;
1600 // Scope of analysis
1602 this(FuncDeclaration fd,Scope* s) scope
1608 /* Checks that the overriden functions (if any) have in contracts if
1609 * funcdecl has an in contract.
1611 void checkInContractOverrides()
1613 if (funcdecl.frequires)
1615 for (size_t i = 0; i < funcdecl.foverrides.length; i++)
1617 FuncDeclaration fdv = funcdecl.foverrides[i];
1618 if (fdv.fbody && !fdv.frequires)
1620 funcdecl.error("cannot have an in contract when overridden function `%s` does not have an in contract", fdv.toPrettyChars());
1628 extern (C++) void semanticTypeInfoMembers(StructDeclaration sd)
1632 sd.xeq.semanticRun < PASS.semantic3done)
1634 uint errors = global.startGagging();
1635 sd.xeq.semantic3(sd.xeq._scope);
1636 if (global.endGagging(errors))
1642 sd.xcmp.semanticRun < PASS.semantic3done)
1644 uint errors = global.startGagging();
1645 sd.xcmp.semantic3(sd.xcmp._scope);
1646 if (global.endGagging(errors))
1647 sd.xcmp = sd.xerrcmp;
1650 FuncDeclaration ftostr = search_toString(sd);
1653 ftostr.semanticRun < PASS.semantic3done)
1655 ftostr.semantic3(ftostr._scope);
1660 sd.xhash.semanticRun < PASS.semantic3done)
1662 sd.xhash.semantic3(sd.xhash._scope);
1666 sd.postblit._scope &&
1667 sd.postblit.semanticRun < PASS.semantic3done)
1669 sd.postblit.semantic3(sd.postblit._scope);
1674 sd.dtor.semanticRun < PASS.semantic3done)
1676 sd.dtor.semantic3(sd.dtor._scope);