Skip to content

Commit 3d7d654

Browse files
committed
review fix
1 parent be13827 commit 3d7d654

2 files changed

Lines changed: 35 additions & 7 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstio/languageserver/requests/MapRequest.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,9 @@ public abstract class MapRequest extends UserRequest<Object> {
7979
public static final String BUILD_COMPILED_LUA_NAME = "02_compiled.lua";
8080
public static final String BUILD_JHCR_SCRIPT_NAME = "03_jhcr_war3map.j";
8181

82+
/** RunArgs flag (see {@link RunArgs}) that relaxes Jass type checks and skips PJass; injected for pre-1.24 targets. */
83+
private static final String LEGACY_JASS_CHECKS_ARG = "-legacyJassChecks";
84+
8285
/**
8386
* makes the compilation slower, but more safe by discarding results from the editor and working on a copy of the model
8487
*/
@@ -102,17 +105,21 @@ public MapRequest(WurstLanguageServer langServer, Optional<File> map, List<Strin
102105
Optional<String> wc3Path, Optional<String> gameExePath) {
103106
this.langServer = langServer;
104107
this.map = map;
105-
this.compileArgs = compileArgs;
106108
this.workspaceRoot = workspaceRoot;
107-
this.runArgs = new RunArgs(compileArgs);
108109
this.wc3Path = wc3Path;
109110
this.buildConfig = WurstBuildConfig.fromWorkspaceRoot(workspaceRoot);
110-
// Patches before 1.24 ship Blizzard common.j/blizzard.j with type mismatches
111-
// that the Jass VM tolerates (e.g. real returned as integer). Relax Jass
112-
// type checks and skip PJass for such targets so these stock scripts compile.
113-
if (buildConfig.isPre124()) {
114-
runArgs.setLegacyJassTypeChecks(true);
111+
// Patches before 1.24 ship Blizzard common.j/blizzard.j with type mismatches that the
112+
// Jass VM tolerates (e.g. a real returned where an integer is declared). Relax Jass type
113+
// checks and skip PJass for such targets so these stock scripts compile. Carry the flag
114+
// through compileArgs so every RunArgs rebuilt from it (compileScript/compileMap) sees it,
115+
// not just this request-level field.
116+
if (buildConfig.isPre124() && !compileArgs.contains(LEGACY_JASS_CHECKS_ARG)) {
117+
List<String> legacyArgs = new ArrayList<>(compileArgs);
118+
legacyArgs.add(LEGACY_JASS_CHECKS_ARG);
119+
compileArgs = legacyArgs;
115120
}
121+
this.compileArgs = compileArgs;
122+
this.runArgs = new RunArgs(compileArgs);
116123
if (gameExePath.isPresent() && StringUtils.isNotBlank(gameExePath.get())) {
117124
Optional<GameVersion> configuredVersion = this instanceof RunMap
118125
? Optional.empty()

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import de.peeeq.wurstio.languageserver.WurstBuildConfig;
66
import de.peeeq.wurstio.languageserver.requests.MapRequest;
77
import de.peeeq.wurstio.languageserver.requests.RunMap;
8+
import de.peeeq.wurstscript.RunArgs;
89
import de.peeeq.wurstio.utils.W3InstallationData;
910
import net.moonlightflower.wc3libs.port.GameVersion;
1011
import org.testng.annotations.Test;
@@ -211,6 +212,22 @@ private static boolean isPatchCompliant(Optional<WurstBuildConfig.Wc3Patch> proj
211212
return (boolean) method.invoke(null, projectKind, clientVersion);
212213
}
213214

215+
@Test
216+
public void pre124PatchPropagatesLegacyJassChecksToCompileArgs() throws Exception {
217+
// Pre-1.24: the flag must be carried in compileArgs so the fresh RunArgs that
218+
// compileScript/compileMap build (RunArgs(compileArgs)) actually relaxes Jass checks + skips PJass.
219+
TestMapRequest legacy = new TestMapRequest(projectWithPatch("v1.23"), Optional.empty(), Optional.empty());
220+
assertTrue(legacy.exposedCompileArgs().contains("-legacyJassChecks"),
221+
"pre-1.24 build must carry -legacyJassChecks in compileArgs: " + legacy.exposedCompileArgs());
222+
assertTrue(new RunArgs(legacy.exposedCompileArgs().toArray(new String[0])).isLegacyJassTypeChecks(),
223+
"a RunArgs rebuilt from compileArgs must report legacy Jass checks");
224+
225+
// Modern target: flag must not be injected.
226+
TestMapRequest modern = new TestMapRequest(projectWithPatch("v2.0"), Optional.empty(), Optional.empty());
227+
assertFalse(modern.exposedCompileArgs().contains("-legacyJassChecks"),
228+
"modern build must not carry the legacy flag: " + modern.exposedCompileArgs());
229+
}
230+
214231
private static Path projectWithPatch(String patch) throws Exception {
215232
Path project = Files.createTempDirectory("wurst-map-request-patch");
216233
Files.createDirectories(project.resolve("wurst"));
@@ -234,6 +251,10 @@ Optional<File> gameExe() {
234251
return w3data.getGameExe();
235252
}
236253

254+
List<String> exposedCompileArgs() {
255+
return compileArgs;
256+
}
257+
237258
@Override
238259
public Object execute(ModelManager modelManager) {
239260
return null;

0 commit comments

Comments
 (0)