Skip to content

Commit 15b90ab

Browse files
committed
Remove duplicate source entries
1 parent 0934fbe commit 15b90ab

File tree

3 files changed

+37
-4
lines changed

3 files changed

+37
-4
lines changed

pkl-core/src/main/java/org/pkl/core/runtime/PowerAssertions.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import java.util.Collections;
2525
import java.util.Comparator;
2626
import java.util.Deque;
27+
import java.util.LinkedHashSet;
2728
import java.util.LinkedList;
2829
import java.util.List;
2930
import java.util.Map;
@@ -208,10 +209,12 @@ private static boolean shouldHide(
208209
return null;
209210
}
210211

211-
private static List<LayerEntry> getLayerEntries(
212+
private static Collection<LayerEntry> getLayerEntries(
212213
Map<Node, List<Object>> trackedValues, SourceSection sourceSection) {
213214
var exprNode = parser.parseExpressionInput(sourceSection.getCharacters().toString());
214-
var ret = new ArrayList<LayerEntry>();
215+
// it's possible that two nodes can turn into identical `SourceEntry`s; ensure these entries are
216+
// distinct by using a set.
217+
var ret = new LinkedHashSet<LayerEntry>();
215218
for (var entry : trackedValues.entrySet()) {
216219
var truffleNode = entry.getKey();
217220
var values = entry.getValue();
@@ -250,7 +253,7 @@ private static boolean canFitMarker(Deque<LayerEntry> layer, LayerEntry elem) {
250253
}
251254

252255
private static List<Collection<LayerEntry>> buildLayers(
253-
List<LayerEntry> layerEntries, SourceSection line) {
256+
Collection<LayerEntry> layerEntries, SourceSection line) {
254257
var sortedSections =
255258
layerEntries.stream()
256259
.filter((it) -> it.startLine() == line.getStartLine())
@@ -339,7 +342,7 @@ private static boolean renderLine(
339342
AnsiStringBuilder out,
340343
String indent,
341344
SourceSection line,
342-
List<LayerEntry> layerEntries,
345+
Collection<LayerEntry> layerEntries,
343346
int trimStart,
344347
@Nullable Consumer<AnsiStringBuilder> lineSuffix) {
345348
var layers = buildLayers(layerEntries, line);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class Bird {
2+
name: String?
3+
}
4+
5+
// this will create `NullPropagatingOperationNode` and `InvokeVirtualMethodNode` for
6+
// `name?.contains("Bob")`.
7+
// this tests that we don't have two duplicate values in the diagram.
8+
p: Bird(name?.contains("Bob") ?? false) = new {
9+
name = "Pigeon"
10+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
–– Pkl Error ––
2+
Type constraint `name?.contains("Bob") ?? false` violated.
3+
Value: new Bird { name = "Pigeon" }
4+
5+
name?.contains("Bob") ?? false
6+
| | |
7+
| false false
8+
"Pigeon"
9+
10+
x | p: Bird(name?.contains("Bob") ?? false) = new {
11+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
at typeConstraints16#p (file:///$snippetsDir/input/errors/power/typeConstraints16.pkl)
13+
14+
xxx | renderer.renderDocument(value)
15+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
16+
at pkl.base#Module.output.text (pkl:base)
17+
18+
xxx | if (renderer is BytesRenderer) renderer.renderDocument(value) else text.encodeToBytes("UTF-8")
19+
^^^^
20+
at pkl.base#Module.output.bytes (pkl:base)

0 commit comments

Comments
 (0)