feat: implement objects moving and borrowing
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
class A
|
||||
{
|
||||
uint some;
|
||||
}
|
||||
|
||||
fn doSome(A a) A
|
||||
{
|
||||
// NOTE: section below won't change `a.some` value
|
||||
|
||||
// if (a.some < 1)
|
||||
// {
|
||||
// a.some = 1;
|
||||
// return a;
|
||||
// }
|
||||
a.some = 1;
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
A a = new A;
|
||||
a.some = 0;
|
||||
printline(a);
|
||||
|
||||
a = doSome(a);
|
||||
printline(a);
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
class Animal
|
||||
{
|
||||
str type;
|
||||
str name;
|
||||
int age;
|
||||
|
||||
fn copy() Animal
|
||||
{
|
||||
Animal cp = new Animal;
|
||||
cp.type = this.type;
|
||||
cp.name = this.name;
|
||||
cp.age = this.age;
|
||||
|
||||
return cp;
|
||||
}
|
||||
}
|
||||
|
||||
Animal a = new Animal;
|
||||
a.type = "Cow";
|
||||
a.name = "Buryatka";
|
||||
a.age = 5;
|
||||
|
||||
Animal b = a.copy();
|
||||
a.name = "Gavryusha";
|
||||
a.age = 10;
|
||||
|
||||
printline(a);
|
||||
printline(b);
|
||||
|
||||
if (a.type == b.type && a.name != b.name && a.age < b.age)
|
||||
printline("Test passed");
|
||||
else
|
||||
printline("Test failed");
|
||||
|
||||
Reference in New Issue
Block a user