Skip to content

Commit 87e60f5

Browse files
authored
Merge pull request dlang#22228 from dlang/stable
Merge stable
2 parents 466d795 + dbf2e20 commit 87e60f5

File tree

15 files changed

+348
-117
lines changed

15 files changed

+348
-117
lines changed

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
v2.112.0-beta.1
1+
v2.112.0

compiler/src/dmd/aggregate.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ class StructDeclaration : public AggregateDeclaration
171171
static StructDeclaration *create(Loc loc, Identifier *id, bool inObject);
172172
StructDeclaration *syntaxCopy(Dsymbol *s) override;
173173
const char *kind() const override;
174-
bool isPOD();
175174
bool zeroInit() const; // !=0 if initialize with 0 fill
176175
bool zeroInit(bool v);
177176
bool hasIdentityAssign() const; // true if has identity opAssign

compiler/src/dmd/cxxfrontend.d

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,12 @@ PURE isPure(FuncDeclaration fd)
512512
return dmd.funcsem.isPure(fd);
513513
}
514514

515+
bool needsClosure(FuncDeclaration fd)
516+
{
517+
import dmd.funcsem;
518+
return dmd.funcsem.needsClosure(fd);
519+
}
520+
515521
/***********************************************************
516522
* hdrgen.d
517523
*/

compiler/src/dmd/declaration.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,12 @@ namespace dmd
3737
bool checkClosure(FuncDeclaration* fd);
3838
MATCH leastAsSpecialized(FuncDeclaration *f, FuncDeclaration *g, ArgumentLabels *names);
3939
PURE isPure(FuncDeclaration *f);
40+
bool needsClosure(FuncDeclaration *fd);
4041
FuncDeclaration *genCfunc(Parameters *args, Type *treturn, const char *name, StorageClass stc=0);
4142
FuncDeclaration *genCfunc(Parameters *args, Type *treturn, Identifier *id, StorageClass stc=0);
4243
bool isAbstract(ClassDeclaration *cd);
4344
bool overloadInsert(Dsymbol *ds, Dsymbol *s);
44-
bool equals(const Dsymbol *ds, const Dsymbol *s);
45+
bool equals(const Dsymbol * const ds, const Dsymbol * const s);
4546
}
4647

4748
//enum STC : ulong from astenums.d:
@@ -719,7 +720,6 @@ class FuncDeclaration : public Declaration
719720
virtual bool addPreInvariant();
720721
virtual bool addPostInvariant();
721722
const char *kind() const override;
722-
bool needsClosure();
723723
bool hasNestedFrameRefs();
724724
ParameterList getParameterList();
725725

compiler/src/dmd/dsymbolsem.d

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3864,24 +3864,6 @@ private extern(C++) final class DsymbolSemanticVisitor : Visitor
38643864
sc.stc &= ~STC.static_; // not a static constructor
38653865

38663866
funcDeclarationSemantic(sc, ctd);
3867-
// Check short constructor: this() => expr;
3868-
if (ctd.fbody)
3869-
{
3870-
if (auto s = ctd.fbody.isExpStatement())
3871-
{
3872-
if (s.exp)
3873-
{
3874-
auto ce = s.exp.isCallExp();
3875-
// check this/super before semantic
3876-
if (!ce || (!ce.e1.isThisExp() && !ce.e1.isSuperExp()))
3877-
{
3878-
s.exp = s.exp.expressionSemantic(sc);
3879-
if (s.exp.type.ty != Tvoid)
3880-
error(s.loc, "can only return void expression, `this` call or `super` call from constructor");
3881-
}
3882-
}
3883-
}
3884-
}
38853867

38863868
sc.pop();
38873869

@@ -9397,7 +9379,7 @@ bool isAbstract(ClassDeclaration cd)
93979379
static int virtualSemantic(Dsymbol s, void*)
93989380
{
93999381
auto fd = s.isFuncDeclaration();
9400-
if (fd && !(fd.storage_class & STC.static_) && !fd.isUnitTestDeclaration())
9382+
if (fd && !(fd.storage_class & STC.static_) && !fd.isUnitTestDeclaration() && !fd.isCtorDeclaration())
94019383
fd.dsymbolSemantic(null);
94029384
return 0;
94039385
}

compiler/src/dmd/globals.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ struct CompileEnv
328328
d_bool transitionIn;
329329
d_bool ddocOutput;
330330
d_bool masm;
331+
DString switchPrefix;
331332
IdentifierCharLookup cCharLookupTable;
332333
IdentifierCharLookup dCharLookupTable;
333334
};

compiler/src/dmd/parse.d

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5332,10 +5332,7 @@ class Parser(AST, Lexer = dmd.lexer.Lexer) : Lexer
53325332
error("missing `do { ... }` after `in` or `out`");
53335333
const returnloc = token.loc;
53345334
nextToken();
5335-
if (f.isCtorDeclaration)
5336-
f.fbody = new AST.ExpStatement(returnloc, parseExpression());
5337-
else
5338-
f.fbody = new AST.ReturnStatement(returnloc, parseExpression());
5335+
f.fbody = new AST.ReturnStatement(returnloc, parseExpression());
53395336
f.endloc = token.loc;
53405337
check(TOK.semicolon);
53415338
break;

compiler/src/dmd/semantic3.d

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,6 +1458,10 @@ private extern(C++) final class Semantic3Visitor : Visitor
14581458
if (ctor.semanticRun >= PASS.semantic3)
14591459
return;
14601460

1461+
if (!ctor.fbody)
1462+
return visit(cast(FuncDeclaration)ctor);
1463+
1464+
14611465
/* If any of the fields of the aggregate have a destructor, add
14621466
* scope (failure) { this.fieldDtor(); }
14631467
* as the first statement of the constructor (unless the constructor
@@ -1468,7 +1472,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
14681472
* https://issues.dlang.org/show_bug.cgi?id=14246
14691473
*/
14701474
AggregateDeclaration ad = ctor.isMemberDecl();
1471-
if (!ctor.fbody || !ad || !ad.fieldDtor ||
1475+
if (!ad || !ad.fieldDtor ||
14721476
global.params.dtorFields == FeatureState.disabled || !global.params.useExceptions || ctor.type.toTypeFunction.isNothrow)
14731477
return visit(cast(FuncDeclaration)ctor);
14741478

@@ -1541,7 +1545,6 @@ private extern(C++) final class Semantic3Visitor : Visitor
15411545
visit(cast(FuncDeclaration)ctor);
15421546
}
15431547

1544-
15451548
override void visit(Nspace ns)
15461549
{
15471550
if (ns.semanticRun >= PASS.semantic3)

compiler/src/dmd/statementsem.d

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2545,16 +2545,44 @@ Statement statementSemanticVisit(Statement s, Scope* sc)
25452545

25462546
if (fd.isCtorDeclaration())
25472547
{
2548-
if (rs.exp)
2548+
// Constructors implicitly do:
2549+
// return this;
2550+
auto ctorReturn = new ThisExp(Loc.initial);
2551+
ctorReturn.type = tret;
2552+
2553+
bool isConstructorCall(Expression e)
25492554
{
2550-
error(rs.loc, "cannot return expression from constructor");
2551-
errors = true;
2555+
auto ce = e.isCallExp();
2556+
if (!ce)
2557+
return false;
2558+
2559+
auto dve = ce.e1.isDotVarExp();
2560+
if (!dve)
2561+
return false;
2562+
2563+
return dve.var.isThis !is null;
25522564
}
25532565

2554-
// Constructors implicitly do:
2555-
// return this;
2556-
rs.exp = new ThisExp(Loc.initial);
2557-
rs.exp.type = tret;
2566+
if (rs.exp)
2567+
{
2568+
rs.exp = rs.exp.expressionSemantic(sc);
2569+
2570+
if (rs.exp.type.ty != Tvoid && !isConstructorCall(rs.exp))
2571+
{
2572+
2573+
error(rs.loc, "can only return void expression, `this` call or `super` call from constructor");
2574+
errors = true;
2575+
rs.exp = ErrorExp.get();
2576+
}
2577+
else
2578+
{
2579+
rs.exp = new CommaExp(rs.loc, rs.exp, ctorReturn).expressionSemantic(sc);
2580+
}
2581+
}
2582+
else
2583+
{
2584+
rs.exp = ctorReturn;
2585+
}
25582586
}
25592587
else if (rs.exp)
25602588
{

compiler/test/compilable/shortened_methods.d

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class A {
2222
class B : A{
2323
// short syntax also overrides the same as long syntax
2424
override bool isNull() => this !is null;
25+
26+
this(float y) => super(y);
2527
}
2628

2729
static assert((new A).x == 34);
@@ -46,6 +48,11 @@ struct T
4648
void inc() {}
4749
this(this) => inc();
4850

51+
// https://github.com/dlang/dmd/issues/21576
52+
this(int) => inc();
53+
54+
this(byte) { return inc(); }
55+
4956
void free() {}
5057
~this() => free();
5158
}

0 commit comments

Comments
 (0)