Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#20927 #20937

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

#20927 #20937

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions compiler/src/dmd/aggregate.h
Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions test/test_opcall.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import std.stdio;

struct Test
{
Test opCall() if false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what's with the if false?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The line Test opCall() if false indicates that the opCall method is conditionally compiled based on the if false statement. This means that the method will not be available or compiled into the program, effectively making it a no-op.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main function creates an instance of Test, which will call the default constructor since opCall is not defined due to the if false condition.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which it should be Test opCall() if (false) (note the parentheses)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The opCall method is defined within the Test struct but is conditionally compiled based on the if (false) statement, meaning it will not be available in the compiled output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code with the if (false) condition in the opCall method. Since the method is conditionally compiled and will not execute, can it will need be modify the condition to if (true) to allow the method to be compiled and executed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

struct Test
{
Test opCall() if (true)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it wright?

{
return Test();
}
}

void main()
{
auto instance = Test(); // This should be interpreted as a constructor call
writeln("Test instance created successfully.");
}