Skip to content

Commit af2a739

Browse files
committed
Fix jass string null translation (#1110)
1 parent 5535ed8 commit af2a739

3 files changed

Lines changed: 43 additions & 41 deletions

File tree

.github/workflows/build.yml

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ jobs:
126126
echo "ERROR: expected at least Win + Linux zips."
127127
exit 1
128128
fi
129+
129130
- name: Normalize nightly filenames
130131
shell: bash
131132
run: |
@@ -139,52 +140,14 @@ jobs:
139140
done
140141
echo "Renamed to:"; ls -alh upload
141142
142-
# Delete old release + tag, then create a fresh one at HEAD
143-
- name: Recreate nightly release and tag at HEAD
144-
uses: actions/github-script@v7
145-
with:
146-
script: |
147-
const { owner, repo } = context.repo;
148-
const tag = 'nightly';
149-
150-
// Delete existing release (if any)
151-
try {
152-
const rel = await github.rest.repos.getReleaseByTag({ owner, repo, tag });
153-
await github.rest.repos.deleteRelease({ owner, repo, release_id: rel.data.id });
154-
core.info(`Deleted release id=${rel.data.id}`);
155-
} catch (e) {
156-
core.info(`No previous release to delete: ${e.message}`);
157-
}
158-
159-
// Delete tag (if any)
160-
try {
161-
await github.rest.git.deleteRef({ owner, repo, ref: `tags/${tag}` });
162-
core.info('Deleted ref tags/nightly');
163-
} catch (e) {
164-
core.info(`No existing tag to delete: ${e.message}`);
165-
}
166-
167-
// Create fresh prerelease at the current commit
168-
const { data: rel2 } = await github.rest.repos.createRelease({
169-
owner, repo,
170-
tag_name: tag,
171-
target_commitish: context.sha,
172-
name: 'Nightly Build (master)',
173-
body: 'Nightly build for the latest commit on `master`.\nThis release is automatically updated on each push.',
174-
draft: false,
175-
prerelease: true,
176-
make_latest: 'false' // MUST be a string
177-
});
178-
core.setOutput('upload_url', rel2.upload_url);
179-
180143
- name: Publish Nightly Release (upload assets)
181144
uses: softprops/action-gh-release@v2
182145
with:
183146
tag_name: nightly
184147
target_commitish: ${{ github.sha }}
185148
prerelease: true
186149
draft: false
187-
make_latest: "false" # keep as string here too
150+
make_latest: "false"
188151
name: Nightly Build (master)
189152
body: |
190153
Nightly build for the latest commit on `master`.
@@ -194,4 +157,3 @@ jobs:
194157
env:
195158
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
196159

197-

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtojass/ExprTranslation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static JassExpr translate(ImNull e, ImToJassTranslator translator) {
6060
} else if (typename.equals("boolean") || typename.equals("bool")) {
6161
return JassExprBoolVal(false);
6262
} else if (typename.equals("string")) {
63-
return JassExprStringVal("");
63+
return JassExprNull();
6464
}
6565
}
6666

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/JurstTests.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.util.Collections;
1313
import java.util.Map;
1414

15+
import static org.testng.AssertJUnit.assertFalse;
1516
import static org.testng.AssertJUnit.assertTrue;
1617

1718
public class JurstTests extends WurstScriptTest {
@@ -340,6 +341,45 @@ public void testKeepTRVEHooked() throws IOException {
340341
assertTrue(output.contains("real myVar"));
341342
}
342343

344+
@Test
345+
public void testStringNullCheckStaysNull() throws IOException {
346+
String jassCode = Utils.string(
347+
"globals",
348+
" string array s__SaveCodes",
349+
" integer PID",
350+
" integer unitSaveID",
351+
"endglobals",
352+
"",
353+
"function main takes nothing returns nothing",
354+
" if s__SaveCodes[PID * 19 + unitSaveID] != null then",
355+
" call BJDebugMsg(\"\")", // could be anything
356+
" endif",
357+
"endfunction"
358+
);
359+
360+
String jurstCode = Utils.string(
361+
"package test",
362+
"endpackage"
363+
);
364+
365+
testJurstWithJass(false, true, jassCode, jurstCode);
366+
367+
File out = new File("./test-output/JurstJassTest_inlopt.j");
368+
String output = com.google.common.io.Files.toString(out, Charsets.UTF_8);
369+
370+
// Ensure the null check survives as a null check
371+
assertTrue(
372+
"Expected string null check to stay != null",
373+
output.contains("s__SaveCodes[PID * 19 + unitSaveID] != null")
374+
);
375+
376+
// And make sure we did NOT silently change it to empty string
377+
assertFalse(
378+
"String null check must not become != \"\"",
379+
output.contains("s__SaveCodes[PID * 19 + unitSaveID] != \"\"")
380+
);
381+
}
382+
343383
private void testJurstWithJass(boolean executeProg, boolean withStdLib, String jass, String jurst) {
344384
Map<String, String> inputs = ImmutableMap.of(
345385
"example.j", jass,

0 commit comments

Comments
 (0)