Skip to content

Closure over old-generic string container emits double stringFromIndex (invalid Jass / interpreter crash) #1445

Closed

Description

@theQuazz

Compiler: 1.9.0.0-nightly-1-g2d53fc14e (installed by wurst4vscode 0.12.29, grill 1.4.0)
Stdlib: wurstStdlib2 master 8ac65c6
Script mode: JASS, wc3Patch: v3.0

Repro

Use a fresh grill generate <name> --script-mode jass project with this as its only package:

package Repro
import LinkedList

interface StringFn
    function get(int i) returns string

let names = asList("a", "b")

init
    StringFn f = i -> names.get(i)
    print(f.get(0))

grill typecheck fails:

Error output.j:754: Generated Jass failed validation: Cannot convert string to integer in parameter index in call to stringFromIndex Please report this compiler error.

Generated Jass:

function get_Repro takes integer this, integer i returns string
	return stringFromIndex(stringFromIndex(dispatch_LinkedList_LinkedList_get(Repro_names, i)))
endfunction

The closure body converts the old-generic LinkedList<string> value back to a string, and so does the closure's return. That's two conversions.

Compile-time variant

The same closure in an @compiletime function crashes the interpreter:

@compiletime function reproCompiletime()
    StringFn f = i -> names.get(i)
    print(f.get(0))
You encountered a bug in the interpreter: java.lang.Error: The native <LoadStr> expects different parameter 2!
    Hashtable.wurst:101 inside call hashtable_loadString(ht690, 2, "a")
    Table.wurst:59 inside call Table_loadString(Table_2, "a")
    TypeCasting.wurst:42 inside call stringFromIndex("a")
    Repro.wurst:10 inside call get_Repro(StringFn_Repro_1, 0)

In a real map this hits object editing, for example AbilityDefinitionSpellBook.presetSpellList(lvl -> abilityList.get(lvl)) with abilityList: HashMap<int, string>.

Control

The same read in a plain function compiles correctly, with a single stringFromIndex:

function getName(int i) returns string
    return names.get(i)
function getName takes integer i returns string
	return stringFromIndex(dispatch_LinkedList_LinkedList_get(Repro_names, i))
endfunction

Seen in Island Troll Tribes with HashMap<int, string> and LinkedList<string> read inside StringLevelClosures. The workaround was to read outside the closure.


Related: debug builds hit Jass limits that release builds don't

These are from the same map, Island Troll Tribes, with JASS mode and grill run, so -stacktraces was on. Neither is a compiler bug as such, but both are easy for a large map to hit, and the first one fails silently until runtime. Worth considering compiler warnings for them.

  1. Hard crash from too many parameters. Vararg calls compile to one Jass parameter per element, and stack traces add a hidden string w__wurst_stackPos parameter. new HashSet<string>()..add(<29 strings>) generated HashSet_add_29 with 31 parameters, and WC3 (3.0.0.24268) crashed with ACCESS_VIOLATION during package init. A 30-element asList(...) produced asList_30 with 31 parameters too. Splitting the calls fixed it. A warning or error when a generated function crosses the limit would have saved a lot of bisecting.

  2. Package init over the op limit. A package with 1,110 public let X = compiletime(GEN.next())..registerObjectID("X") globals died at Add doc comments #1,096 with "Could not initialize package". Moving each registration into execute() fixed it.

Activity

  1. Frotty commented on Oct 13, 2026

    @Frotty
    Member

    The old-generic closure bug is reproduced and fixed in #1446. Expression translation already decoded the container's result, and closure-return translation decoded it again. The fix emits one stringFromIndex call. Runtime and compile-time repros fail before the fix and pass afterward; regression coverage includes Jass, Lua, and a new-generic control.

    For the debug-build observations:

    • The claim that 31 parameters exceeds the Jass limit is incorrect: 31 works; 32 is the failing boundary. Measured on Warcraft III 3.0.0.24268, matching this report: calls with 30/31 integer or string parameters passed, including an integer receiver + 29 strings + a string trace position, and a 31-string call during package initialization. Both 32-parameter maps initialized, then the client process exited. Wurst already rejects expanded vararg calls above 31 emitted Jass parameters, including receivers, tuple components, and injected stacktrace parameters; pjass also rejects calls with 32 arguments. The PR adds pjass regression coverage. If the original crashing function really had only 31 emitted parameters, that crash has another cause; the signature alone did not reproduce it.
    • Package-init operation limits are a runtime budget, not a Jass syntax or argument-count error. pjass cannot determine the work executed by initialization and its callees. Stacktrace instrumentation adds runtime work, so debug builds can hit that budget sooner; moving work to separate execution threads gives it separate budgets.

    Use the default Lua target unless you need Jass compatibility. Lua avoids this Jass-specific argument limit, so new maps should not opt into Jass mode without a compatibility requirement.

    New generics are also recommended. Prefer new-generic containers where they fit, e.g. asArrayList(...) / ArrayList<T:> for indexed lists and IntMap<V:> for integer-keyed maps. They preserve native value representations rather than routing strings through integer indices, avoiding this particular conversion bug and its overhead. The existing LinkedList, HashMap, and HashSet declarations still use old generics, so changing surrounding code to new generics does not migrate those containers. New generics do not remove Jass's parameter or operation limits if you continue targeting Jass; the old-generic compiler bug is fixed independently.

    Validation: 106 focused compiler tests passed, plus the real-client parameter probes above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions