@@ -115,9 +115,8 @@ abstract class AstCodeGenerator
115115
116116 w.ValueType translateType (DartType type) => translator.translateType (type);
117117
118- w.Local addLocal (w.ValueType type) {
119- return b.addLocal (type);
120- }
118+ w.Local addLocal (w.ValueType type, {String ? name}) =>
119+ b.addLocal (type, name: name);
121120
122121 DartType dartTypeOf (Expression exp) {
123122 if (exp is ConstantExpression ) {
@@ -257,7 +256,12 @@ abstract class AstCodeGenerator
257256 int index,
258257 Constant ? defaultValue,
259258 bool isRequired) {
260- w.Local local = paramLocals[implicitParams + index];
259+ final localIndex = implicitParams + index;
260+ w.Local local = paramLocals[localIndex];
261+ final variableName = variable.name;
262+ if (variableName != null ) {
263+ b.localNames[local.index] = variableName;
264+ }
261265 if (defaultValue == ParameterInfo .defaultValueSentinel) {
262266 // The default value for this parameter differs between implementations
263267 // within the same selector. This means that callers will pass the
@@ -357,7 +361,8 @@ abstract class AstCodeGenerator
357361 if (local.type == w.RefType .extern (nullable: true ) &&
358362 ! (parameterType is InterfaceType &&
359363 parameterType.classNode == translator.wasmExternRefClass)) {
360- w.Local newLocal = addLocal (translateType (parameterType));
364+ w.Local newLocal =
365+ addLocal (translateType (parameterType), name: parameter.name);
361366 b.local_get (local);
362367 translator.convertType (b, local.type, newLocal.type);
363368 b.local_set (newLocal);
@@ -490,9 +495,10 @@ abstract class AstCodeGenerator
490495 member.isInstanceMember || reference.isConstructorBodyReference;
491496 if (hasThis) {
492497 thisLocal = paramLocals[0 ];
498+ b.localNames[thisLocal! .index] = "this" ;
493499 final preciseThisType = translator.preciseThisFor (member);
494500 if (translator.needsConversion (thisLocal! .type, preciseThisType)) {
495- preciseThisLocal = addLocal (preciseThisType);
501+ preciseThisLocal = addLocal (preciseThisType, name : "preciseThis" );
496502 b.local_get (thisLocal! );
497503 translator.convertType (b, thisLocal! .type, preciseThisType);
498504 b.local_set (preciseThisLocal! );
@@ -537,9 +543,10 @@ abstract class AstCodeGenerator
537543 }
538544
539545 if (context.containsThis) {
540- thisLocal = addLocal (context
541- .struct.fields[context.thisFieldIndex].type.unpacked
542- .withNullability (false ));
546+ thisLocal = addLocal (
547+ context.struct.fields[context.thisFieldIndex].type.unpacked
548+ .withNullability (false ),
549+ name: "this" );
543550 preciseThisLocal = thisLocal;
544551
545552 b.struct_get (context.struct, context.thisFieldIndex);
@@ -794,7 +801,7 @@ abstract class AstCodeGenerator
794801 w.Local ? local;
795802 Capture ? capture = closures.captures[node];
796803 if (capture == null || ! capture.written) {
797- local = addLocal (type);
804+ local = addLocal (type, name : node.name );
798805 locals[node] = local;
799806 }
800807
@@ -836,7 +843,7 @@ abstract class AstCodeGenerator
836843 w.Local ? local;
837844 final Capture ? capture = closures.captures[node];
838845 if (capture == null || ! capture.written) {
839- local = addLocal (type);
846+ local = addLocal (type, name : node.name );
840847 locals[node] = local;
841848 }
842849
@@ -1352,7 +1359,8 @@ abstract class AstCodeGenerator
13521359 // Since the flow of the return value through the returnValueLocal
13531360 // crosses control-flow constructs, the local needs to always have a
13541361 // defaultable type in order for the Wasm code to validate.
1355- returnValueLocal ?? = addLocal (returnType.withNullability (true ));
1362+ returnValueLocal ?? =
1363+ addLocal (returnType.withNullability (true ), name: "returnValue" );
13561364 b.local_set (returnValueLocal! );
13571365 }
13581366 b.br (returnFinalizers.last.label);
0 commit comments