From 9307b34af6e9483b29c11c8466ebac101c3698fe Mon Sep 17 00:00:00 2001 From: TermiNexus Date: Fri, 9 Oct 2026 18:44:44 +0800 Subject: [PATCH] =?UTF-8?q?test(new):=20NewTest=20=E8=A1=A5=20(6)=20?= =?UTF-8?q?=E6=8B=AC=E5=8F=B7=E5=8F=AF=E7=9C=81=20+=20=E6=A0=87=E9=87=8F/?= =?UTF-8?q?=E6=95=B0=E7=BB=84=E9=9B=B6=E5=88=9D=E5=A7=8B=E5=8C=96=E7=94=A8?= =?UTF-8?q?=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- NewTest/App/main.vp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/NewTest/App/main.vp b/NewTest/App/main.vp index 2b8ecd8..927621c 100644 --- a/NewTest/App/main.vp +++ b/NewTest/App/main.vp @@ -61,6 +61,19 @@ export def main() -> int: stdio.printf("generic-in-pool: %d\n", b.v) stdlib.free(arena2) + # (6) 括号可省 + 标量/数组:`new stack char` / `new stack [4]char`(类型按**注解规则**解析, + # 故 `[N]T` 前导数组声明符与 `T*` 后缀都认)。数组返回**首元素指针**(数组名退化), + # 所以能直接存进 `char*`;未写到的位置是零初始化。 + c6: char* = new stack char + if c6[0] != 0: return 1 + l6: char* = new stack [4]char + l6[0] = 'A' + l6[1] = 'B' + if l6[0] != 'A': return 2 + if l6[1] != 'B': return 3 + if l6[3] != 0: return 4 + stdio.printf("scalar/array: ok\n") + # 非法组合(应报 LifetimeError)——要验证时打开其中一条: # 1) 语义矛盾:bad: Point* = new stack hlife Point(7, 8) # 2) 多来源 :new stack heap Point(7, 8) → 解析期报错