Neat-Lang / neat

The Neat Language compiler. Early beta?
BSD 3-Clause "New" or "Revised" License
110 stars 9 forks source link

Struct copy semantics #23

Closed FeepingCreature closed 1 year ago

FeepingCreature commented 1 year ago

Discussed in https://github.com/Neat-Lang/neat/discussions/22

Originally posted by **ntrel** January 2, 2023 Hi, I'm trying to understand the following: ```d module dtor; import std.stdio; struct S { int i; this(S){print("copy");} ~this(){print("dtor");} } void f(S s) {"f: $(s.i)".print;} void main() { mut S s; { S t = s; // copy s.i++; "$(s.i), $(t.i)".print; // dtor } "call:".print; s.f; // doesn't call copy or dtor "end".print; } ``` Why does calling `f` avoid calling the copy constructor and destructor, but `t` doesn't?
FeepingCreature commented 1 year ago

Fixed on master: https://github.com/Neat-Lang/neat/commit/7527d82c319010fa120120b6fac9605a9a295365