#1752·penrose

Bug: can't pass duplicate `Number` literals to the same constructor

Author: keenancraneCreated May 22, 2024Updated Oct 29, 2024
Labelskind:bugsystem:stylesystem:substanceannoying-but-importantsystem:compiler

There's a strange bug with literals in Substance where diagrams break if you try to pass the same literal in multiple arguments of the same constructor. For example, consider this program that draws points with specified (x,y) coordinates:

-- example.domain
type Point
constructor Point( Number x, Number y )
-- example.style
canvas {
  width = 400
  height = 400
}

forall Point p; Number x,y
where p := Point(x,y) {
  shape C = Circle {
    center: (x,y)
    r: 2
    fillColor: #000
  }
}
--- example.substance
Point a := Point(0,1)
Point b := Point(10,11)
Point c := Point(20,21)

This example works fine, producing three dots along a diagonal line: image

However, if we change the coordinates so that x=y for, say, the second point, we get a result like this (middle point disappears):

Point a := Point(0,1)
Point b := Point(10,10)
Point c := Point(20,21)
image

Likewise if we put point a at (0,0) or point c at (20,20), it does not get drawn.

Could it be that the Style compiler is treating two identical literals as non-distinct Number instances (hence the Style pattern doesn't match)?