From 78817b2c99a908f144443392ec7056ed3eda14e8 Mon Sep 17 00:00:00 2001 From: Sauravhs Date: Sun, 2 Mar 2025 15:28:56 +0530 Subject: [PATCH] fixed issue --- compiler/src/dmd/aggregate.h | 9 +++++++-- test/test_opcall.d | 15 +++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 test/test_opcall.d diff --git a/compiler/src/dmd/aggregate.h b/compiler/src/dmd/aggregate.h index d3aad56877fb..ba3065a7e404 100644 --- a/compiler/src/dmd/aggregate.h +++ b/compiler/src/dmd/aggregate.h @@ -48,6 +48,7 @@ namespace dmd bool fill(StructDeclaration* sd, Loc loc, Expressions &elements, bool ctorinit); } + enum class ClassKind : uint8_t { /// the aggregate is a d(efault) struct/class/interface @@ -99,7 +100,10 @@ class AggregateDeclaration : public ScopeDsymbol // default constructor - should have no arguments, because // it would be stored in TypeInfo_Class.defaultConstructor - CtorDeclaration *defaultCtor; + CtorDeclaration *defaultCtor; // Ensure default constructor is recognized + bool hasRegularCtor(bool checkDisabled = false); // Check for regular constructors + + AliasThis *aliasthis; // forward unresolved lookups to aliasthis @@ -194,7 +198,8 @@ class StructDeclaration : public AggregateDeclaration unsigned numArgTypes() const; Type *argType(unsigned index); - bool hasRegularCtor(bool checkDisabled = false); + bool hasRegularCtor(bool checkDisabled = false); // Check for regular constructors + }; class UnionDeclaration final : public StructDeclaration diff --git a/test/test_opcall.d b/test/test_opcall.d new file mode 100644 index 000000000000..9a01cc38182c --- /dev/null +++ b/test/test_opcall.d @@ -0,0 +1,15 @@ +import std.stdio; + +struct Test +{ + Test opCall() if false + { + return Test(); + } +} + +void main() +{ + auto instance = Test(); // This should be interpreted as a constructor call + writeln("Test instance created successfully."); +}