From 5c48f4038b7c6f33db1efdad143c6110d5ae0063 Mon Sep 17 00:00:00 2001 From: Luke Date: Mon, 1 Sep 2025 15:33:33 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E9=87=8D=E6=9E=84=20Student=20?= =?UTF-8?q?=E7=B1=BB=E5=B9=B6=E7=AE=80=E5=8C=96=20Main=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- playground/Demo/Demo32/Main.snow | 101 +++++++++++++++---------------- 1 file changed, 50 insertions(+), 51 deletions(-) diff --git a/playground/Demo/Demo32/Main.snow b/playground/Demo/Demo32/Main.snow index 83be96b..0471cdd 100644 --- a/playground/Demo/Demo32/Main.snow +++ b/playground/Demo/Demo32/Main.snow @@ -1,56 +1,55 @@ module: main - struct: Student extends Person - fields: - declare studentId: int - init: - params: - name: int - studentId: int - body: - super(name) - this.studentId = studentId - end body - end init + import: os - // 新增:无参数构造 - init: - params: - body: - super(0) - this.studentId = 0 - end body - end init + struct: Student + fields: + declare name: int + declare studentId: int - // 新增:只带 name - init: - params: - name: int - body: - super(name) - this.studentId = -1 - end body - end init + init: + params: + name: int + studentId: int + body: + this.name = name + this.studentId = studentId + end body + end init - function: getStudentId - returns: int - body: - return this.studentId - end body - end function - end struct + init: + params: + body: + this.name = 0 + this.studentId = 0 + end body + end init - function: main - returns: void - body: - declare a: Student = new Student(123, 1001) - declare b: Student = new Student() - declare c: Student = new Student(88) - os.println(a.getName()) // 123 - os.println(a.getStudentId()) // 1001 - os.println(b.getName()) // 0 - os.println(b.getStudentId()) // 0 - os.println(c.getName()) // 88 - os.println(c.getStudentId()) // -1 - end body - end function -end module \ No newline at end of file + init: + params: + name: int + body: + this.name = name + this.studentId = -1 + end body + end init + + function: getStudentId + returns: int + body: + return this.studentId + end body + end function + end struct + + function: main + returns: void + body: + declare a: Student = new Student(123, 1001) + declare b: Student = new Student() + declare c: Student = new Student(88) + println(a.getStudentId()) + println(b.getStudentId()) + println(b.getStudentId()) + end body + end function +end module