Skip to content

Commit f9778b0

Browse files
committed
Fix regression in blocks returning multiple meshes
1 parent e103709 commit f9778b0

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

ShapeScript/Interpreter.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,12 @@ extension Definition {
857857
"value cannot be assigned a name"
858858
)
859859
}
860-
} else if context.name.isEmpty {
860+
} else if context.name.isEmpty,
861+
// Manage backwards compatibility for blocks that return
862+
// multiple meshes to be used inside difference block
863+
!children.contains(where: { $0.type == .mesh }) ||
864+
children.contains(where: { ![.mesh, .path].contains($0.type) })
865+
{
861866
return .tuple(children.map {
862867
switch $0 {
863868
case let .path(path):

ShapeScriptTests/InterpreterTests.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,6 +1388,19 @@ class InterpreterTests: XCTestCase {
13881388
}
13891389
}
13901390

1391+
func testBlockReturnsGroupedMeshes() throws {
1392+
let program = try parse("""
1393+
define foo {
1394+
cube { size 0.5 }
1395+
cube { size 0.8 }
1396+
}
1397+
foo
1398+
""")
1399+
let context = EvaluationContext(source: program.source, delegate: nil)
1400+
XCTAssertNoThrow(try program.evaluate(in: context))
1401+
XCTAssertEqual(context.children.count, 1)
1402+
}
1403+
13911404
// MARK: Ranges
13921405

13931406
func testRange() {

0 commit comments

Comments
 (0)