@@ -47,6 +47,67 @@ public void classes_method() throws IOException {
4747 testAssertOkFile (new File (TEST_DIR + "Classes_method.wurst" ), true );
4848 }
4949
50+ @ Test
51+ public void jassKeepsTypeIdGlobalsWhenDestroyGuardReadsThem () throws IOException {
52+ testAssertOkLines (false ,
53+ "package test" ,
54+ " class Reference<T>" ,
55+ " T value" ,
56+ "" ,
57+ " init" ,
58+ " let r = new Reference<int>" ,
59+ " destroy r" ,
60+ "endpackage"
61+ );
62+
63+ String opt = Files .readString (new File (TEST_OUTPUT_PATH + "ClassesTests_jassKeepsTypeIdGlobalsWhenDestroyGuardReadsThem_opt.j" ).toPath (), StandardCharsets .UTF_8 );
64+ assertTrue (opt .contains ("integer array Reference_nextFree" ),
65+ "Expected generated Jass to keep the Reference_nextFree global declaration.\n " + opt );
66+ assertTrue (opt .contains ("integer Reference_firstFree=0" ),
67+ "Expected generated Jass to keep the Reference_firstFree global declaration.\n " + opt );
68+ assertTrue (opt .contains ("integer Reference_maxIndex=0" ),
69+ "Expected generated Jass to keep the Reference_maxIndex global declaration.\n " + opt );
70+ assertTrue (opt .contains ("integer array Reference_typeId" ),
71+ "Expected generated Jass to keep the Reference_typeId global declaration.\n " + opt );
72+ assertTrue (opt .contains ("Reference_typeId[obj]" ),
73+ "Expected generated Jass to still reference Reference_typeId in destroy/dispatch logic." );
74+ assertTrue (opt .contains ("Reference_nextFree[Reference_firstFree]" ),
75+ "Expected generated Jass to still reference the recycle stack globals." );
76+ }
77+
78+ @ Test
79+ public void jassNewGenericsRebuildsClassManagementVarsAfterCompiletime () throws IOException {
80+ test ()
81+ .runCompiletimeFunctions (true )
82+ .executeProg (false )
83+ .lines (
84+ "package test" ,
85+ " class Reference<T:>" ,
86+ " T val" ,
87+ " construct(T val)" ,
88+ " this.val = val" ,
89+ "" ,
90+ " class Box" ,
91+ "" ,
92+ " constant compiletimeRef = new Reference<int>(0)" ,
93+ "" ,
94+ " init" ,
95+ " let r = new Reference<int>(1)" ,
96+ " destroy r" ,
97+ " let s = new Reference<bool>(true)" ,
98+ " destroy s" ,
99+ "endpackage"
100+ );
101+
102+ String opt = Files .readString (new File (TEST_OUTPUT_PATH + "ClassesTests_jassNewGenericsRebuildsClassManagementVarsAfterCompiletime_opt.j" ).toPath (), StandardCharsets .UTF_8 );
103+ assertTrue (opt .contains ("integer array Reference_integer__typeId" ),
104+ "Expected generated Jass to declare integer-specialized class-management globals.\n " + opt );
105+ assertTrue (opt .contains ("integer array Reference_boolean__typeId" ),
106+ "Expected generated Jass to declare boolean-specialized class-management globals.\n " + opt );
107+ assertFalse (opt .contains ("Reference_typeId[" ),
108+ "Expected specialized generic lifecycle code not to reference undeclared raw Reference_typeId." );
109+ }
110+
50111 @ Test
51112 public void dispatchNarrowingUsesStaticReceiverTypeInJass () throws IOException {
52113 testAssertOkLines (true ,
0 commit comments