mirror of
https://github.com/dlang/dmd.git
synced 2025-04-26 13:10:12 +03:00
Fix error when struct initializer isn't accepted (#21086)
* Fix error when struct initializer isn't accepted * Rename StructDeclaration.hasRegularCtor parameter to ignoreDisabled checkDisabled detected disabled ctors when it was false, which was confusing! * Update tests
This commit is contained in:
parent
3142290b6f
commit
13b0745e33
6 changed files with 16 additions and 11 deletions
|
@ -196,7 +196,7 @@ public:
|
|||
|
||||
unsigned numArgTypes() const;
|
||||
Type *argType(unsigned index);
|
||||
bool hasRegularCtor(bool checkDisabled = false);
|
||||
bool hasRegularCtor(bool ignoreDisabled = false);
|
||||
};
|
||||
|
||||
class UnionDeclaration final : public StructDeclaration
|
||||
|
|
|
@ -399,13 +399,12 @@ extern (C++) class StructDeclaration : AggregateDeclaration
|
|||
* is not disabled.
|
||||
*
|
||||
* Params:
|
||||
* checkDisabled = if the struct has a regular
|
||||
non-disabled constructor
|
||||
* ignoreDisabled = true to ignore disabled constructors
|
||||
* Returns:
|
||||
* true, if the struct has a regular (optionally,
|
||||
* not disabled) constructor, false otherwise.
|
||||
*/
|
||||
final bool hasRegularCtor(bool checkDisabled = false)
|
||||
final bool hasRegularCtor(bool ignoreDisabled = false)
|
||||
{
|
||||
if (!ctor)
|
||||
return false;
|
||||
|
@ -415,7 +414,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration
|
|||
{
|
||||
if (auto td = s.isTemplateDeclaration())
|
||||
{
|
||||
if (checkDisabled && td.onemember)
|
||||
if (ignoreDisabled && td.onemember)
|
||||
{
|
||||
if (auto ctorDecl = td.onemember.isCtorDeclaration())
|
||||
{
|
||||
|
@ -428,7 +427,7 @@ extern (C++) class StructDeclaration : AggregateDeclaration
|
|||
}
|
||||
if (auto ctorDecl = s.isCtorDeclaration())
|
||||
{
|
||||
if (!ctorDecl.isCpCtor && (!checkDisabled || !(ctorDecl.storage_class & STC.disable)))
|
||||
if (!ctorDecl.isCpCtor && (!ignoreDisabled || !(ctorDecl.storage_class & STC.disable)))
|
||||
{
|
||||
result = true;
|
||||
return 1;
|
||||
|
|
|
@ -7441,7 +7441,7 @@ public:
|
|||
void accept(Visitor* v) override;
|
||||
uint32_t numArgTypes() const;
|
||||
Type* argType(uint32_t index);
|
||||
bool hasRegularCtor(bool checkDisabled = false);
|
||||
bool hasRegularCtor(bool ignoreDisabled = false);
|
||||
};
|
||||
|
||||
class UnionDeclaration final : public StructDeclaration
|
||||
|
|
|
@ -153,7 +153,10 @@ Initializer initializerSemantic(Initializer init, Scope* sc, ref Type tx, NeedIn
|
|||
// that is not disabled.
|
||||
if (sd.hasRegularCtor(true))
|
||||
{
|
||||
error(i.loc, "%s `%s` has constructors, cannot use `{ initializers }`, use `%s( initializers )` instead", sd.kind(), sd.toChars(), sd.toChars());
|
||||
error(i.loc, "Cannot use %s initializer syntax for %s `%s` because it has a constructor",
|
||||
sd.kind(), sd.kind(), sd.toChars());
|
||||
errorSupplemental(i.loc, "Use `%s( arguments )` instead of `{ initializers }`",
|
||||
sd.toChars());
|
||||
return err();
|
||||
}
|
||||
sd.size(i.loc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue