Skip to content

Commit f7e5ff3

Browse files
pbackusdlang-bot
authored andcommitted
Fix Issue 22229 - Struct initialization via constructor missing from language spec
1 parent c3ab2f4 commit f7e5ff3

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

spec/struct.dd

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,9 +273,29 @@ S s = t; // s.a is set to 3
273273
----
274274
)
275275

276-
$(P If $(D opCall) is overridden for the struct, and the struct
277-
is initialized with a value that is of a different type,
278-
then the $(D opCall) operator is called:)
276+
$(P If the struct has a $(LINK2 #struct-constructor, constructor), and
277+
the struct is initialized with a value that is of a different type,
278+
then the constructor is called:)
279+
280+
$(SPEC_RUNNABLE_EXAMPLE_RUN
281+
----
282+
struct S
283+
{
284+
int a;
285+
286+
this(int v)
287+
{
288+
this.a = v;
289+
}
290+
}
291+
292+
S s = 3; // sets s.a to 3 using S's constructor
293+
----
294+
)
295+
296+
$(P If the struct does not have a constructor but $(D opCall) is
297+
overridden for the struct, and the struct is initialized with a value
298+
that is of a different type, then the $(D opCall) operator is called:)
279299

280300
$(SPEC_RUNNABLE_EXAMPLE_RUN
281301
----

0 commit comments

Comments
 (0)