mirror of
https://github.com/apple/pkl.git
synced 2026-03-31 22:23:18 +02:00
fix bug with for generator variables in mixin (#297)
This commit is contained in:
@@ -61,6 +61,7 @@ public final class AmendFunctionNode extends PklNode {
|
|||||||
} else {
|
} else {
|
||||||
parameterSlots = new int[0];
|
parameterSlots = new int[0];
|
||||||
}
|
}
|
||||||
|
var hasForGenVars = false;
|
||||||
for (var i = 0; i < hostFrameDesecriptor.getNumberOfSlots(); i++) {
|
for (var i = 0; i < hostFrameDesecriptor.getNumberOfSlots(); i++) {
|
||||||
var slotInfo = hostFrameDesecriptor.getSlotInfo(i);
|
var slotInfo = hostFrameDesecriptor.getSlotInfo(i);
|
||||||
// Copy for-generator variables from the outer frame descriptor into inner lambda.
|
// Copy for-generator variables from the outer frame descriptor into inner lambda.
|
||||||
@@ -74,10 +75,22 @@ public final class AmendFunctionNode extends PklNode {
|
|||||||
// frame (e.g. with `new Mixin { ... }` syntax), so it injects for-generator vars into the
|
// frame (e.g. with `new Mixin { ... }` syntax), so it injects for-generator vars into the
|
||||||
// wrong frame.
|
// wrong frame.
|
||||||
//
|
//
|
||||||
// As a remedy, we simply copy outer for-generator variables into this frame.
|
// As a remedy, we simply copy outer variables into this frame if there are any for generator
|
||||||
|
// variables.
|
||||||
|
//
|
||||||
|
// We need to preserve the frame slot index, so we insert dummy identifiers
|
||||||
|
// for other slots that aren't for generator variables.
|
||||||
if (slotInfo != null && slotInfo.equals(SymbolTable.FOR_GENERATOR_VARIABLE)) {
|
if (slotInfo != null && slotInfo.equals(SymbolTable.FOR_GENERATOR_VARIABLE)) {
|
||||||
|
if (!hasForGenVars) {
|
||||||
|
hasForGenVars = true;
|
||||||
|
for (var j = 0; j < i; j++) {
|
||||||
|
builder.addSlot(FrameSlotKind.Illegal, Identifier.DUMMY, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
builder.addSlot(
|
builder.addSlot(
|
||||||
hostFrameDesecriptor.getSlotKind(i), hostFrameDesecriptor.getSlotName(i), null);
|
hostFrameDesecriptor.getSlotKind(i), hostFrameDesecriptor.getSlotName(i), null);
|
||||||
|
} else if (hasForGenVars) {
|
||||||
|
builder.addSlot(FrameSlotKind.Illegal, Identifier.DUMMY, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var objectToAmendSlot = builder.addSlot(FrameSlotKind.Object, new Object(), null);
|
var objectToAmendSlot = builder.addSlot(FrameSlotKind.Object, new Object(), null);
|
||||||
|
|||||||
@@ -152,6 +152,9 @@ public final class Identifier implements Comparable<Identifier> {
|
|||||||
// common in lambdas etc
|
// common in lambdas etc
|
||||||
public static final Identifier IT = get("it");
|
public static final Identifier IT = get("it");
|
||||||
|
|
||||||
|
// dummy, unrepresentable identifier
|
||||||
|
public static final Identifier DUMMY = get("`#_");
|
||||||
|
|
||||||
private final String name;
|
private final String name;
|
||||||
|
|
||||||
private Identifier(String name) {
|
private Identifier(String name) {
|
||||||
|
|||||||
@@ -38,3 +38,13 @@ function mapEnvLiteral(_env: Dynamic) = (it) -> (it) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function addElements(keys: List<String>): Mixin<Mapping<String, String>> = new {
|
||||||
|
for (key in keys) {
|
||||||
|
[key] = key
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
res = new Mapping<String, String> {
|
||||||
|
["base"] = "alreadyThere"
|
||||||
|
} |> addElements(List("newElement"))
|
||||||
|
|||||||
@@ -36,3 +36,7 @@ foo {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
res {
|
||||||
|
["base"] = "alreadyThere"
|
||||||
|
["newElement"] = "newElement"
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user